DOSBox runs 16 bit x86 real-mode code under emulation. The regular GCC compiler on OSX 10.6 targets the OSX operating system and 32 bit x86 protected mode, so you cannot use that to build code to run in DOSBox.
What you may be able to do is run a DOS compiler in DOSBox itself. DJGPP is an MS-DOS port of GCC, however it generates 32bit protected mode code targetted at the DPMI subsystem. It is not clear to me that DOSBox supports DPMI, but I imagine that it does, and DJGPP itself is in the DOSBox compatability list, so one would imagine that the code it generates might run also if it does not do anything too out of the ordinary to the emulated hardware.
Borland Turbo C is also on the compatability list, and TC 2.01 is legitimately available for free. Other versions are offered for download elsewhare, but I doubt the legality of such distribution.
A more robust solution however is probably to install a genuine MS-DOS or DOS compatible OS in a Virtual Machine hosted on OSX using VirtualBox. If you do not have a copy of MS-DOS, you might try FreeDOS.