I have installed MS-DOS 6.22 on a VirtualBox virtual machine, everything is working well, the purpose of doing that is to compile a program written in the C language that displays and edits bits in the (virtual) RAM. However, I need a way to install a C compiler on the virtual MS-DOS operating system.
Here are a bunch of details others have missed:
Nobody mentioned DJGPP at all.
It's a protected-mode DOS port of GCC and probably has the largest selection of libraries and guides available of any of the open-source options. (Including a Turbo Vision port with an installation HOWTO)
No matter what you're trying to do, OpenWatcom (source) is likely to meet your needs.
OpenWatcom still includes the free license to use DOS/4GW that made it so popular back in the day. (When you see a game like DOOM saying "DOS/4GW Protected Mode Runtime" when it starts, that means that it was built using Watcom C/C++, because DOS/4GW is the special Watcom bundle version of DOS/4G.)
In fact, DOS/4GW's creator was trying to dig up the source code for a newer version of DOS/4GW to contribute to Open Watcom when he passed away.
If you don't want nostalgia, OpenWatcom bundles newer, better alternatives to DOS/4GW, like DOS/32 and PMODE/W.
If you want to putter around with Windows 3.1 programming, OpenWatcom includes Win386, a 32-bit extender for Window 3.x which was used by companies like Sierra for their Windows 3.1 games before Microsoft produced their own "Win32s" 32-bit API addon.
OpenWatcom can target all supported platforms from a single install. (I use it to build various DOS and Windows test EXEs from Linux.)
OpenWatcom can target a lot of retro-platforms:
If your project must run in real mode (ie. no DJGPP) and you want something with a more modern optimizer than the one in Open Watcom C/C++, there's a fork of GCC named GCC IA16 that you can try. (Though I don't know how complete its support is for the various memory models and calling conventions used in the 16-bit x86 ecosystem.)
If you want something that'll let you run the IDE and compiler on ancient hardware, the Pacific C compiler and IDE list a 286 CPU as their minimum requirement but can also be run in DOSEMU for easy integration into Linux-based build automation.
Here are a few other free C compilers for DOS, though they lack the huge ecosystems DJGPP and OpenWatcom have:
You may also want to run the UPX compressor on the EXE files you build so you'll have more free space on any floppy images you make. (Don't forget to run it with --8086
if you're targeting something older than a 386.)
It's capable of compressing EXE, COM, and SYS files and using this sort of executable compression was commonplace back in the day.
(However, two of the three major formats UPX doesn't compress are OS/2 and Windows 3.1 executables. I'm still looking into the best option for those, given that LxLite doesn't get along with OpenWatcom-generated EXEs.)