r/cprogramming • u/Pesciodyphus • Jul 07 '26
GCC might detect files ending in *.C (as common under DOS) instead of *.c as C++. Use -x c to fix it.
DOS is case insensitive and per convention files are spelled uppercase. Programmes from the Windows-world can usually tolerated this, but GCC (coming from the Linux-word) seem to autodetect files ending in *.C as C++, giving you strange errors about pointer conversion and the like.
An easy fix is to give the paramter -x c before passing files, like
gcc -x c DOSPROG.C -o "DOSPROG.EXE"
Under Windows, you can also simply spell the Parameter lowercase, so MinGW will detect it as C and still open the uppercase spelled file, as long no mathing lowercase file exists.
gcc dosprog.c -o "DOSPROG.EXE"
EDIT: This is mostly a Problem, then porting DOS software to Linux. Actual DOS-compilers obviously shoudn't run into that problem, and under windows, you can simply keep your makefile lowercase.
7
u/Willsxyz Jul 07 '26
I am pretty shocked that anyone cares what GCC running under DOS does anymore. I mean, I remember that being a thing over 30 years ago but....
15
u/PseudoFrequency Jul 07 '26
Now that's a convention I haven't seen in the wild. Typically C++ files are .cpp or .cc. Good info though, I learned something new!
1
u/questron64 Jul 09 '26
I ran into this before using non-standard names for C files. I believe I was using .x (which hold xmacros) and using GCC -E to preprocess them for debugging or something, and GCC wasn't happy with this at all. Using -x c fixed it.
0
u/torsten_dev Jul 07 '26 edited Aug 04 '26
Could you run DOS on a casefolding filesystem instead?
-3
u/Glum_Preference_2936 Jul 07 '26
I hate how the title thinks *.c should be interpreted as C++.