Reputation: 6984
I am using the MinGW compiler for Windows. I am making some programs in C. Most of the articles I read up on this seem to be outdated... last I read C99 was incomplete in the GCC is this still true? My real question is cross platform compatibility between setting C99 and GNU99... should I avoid using GNU99 setting and it's extensions and just stick with C99? I am new to this MinGW compiler set as I have always used Visual Studio and decided to try something new... right now I am compiling with these settings...
-march=native -O3 -std=gnu99
Is there any recommended compiler commands I should enter for making C programs and also for making C++ programs with this compiler?
I want to make a simple program that is compatible with Windows, Mac, & Linux but first most Windows.
Upvotes: 3
Views: 5173
Reputation: 158629
With respect to C, Visual Studio
until recently did not support C99 at all.
With respect to gcc
you can find a detailed detailed writeup on which standard they support and the nooks and crannies involved. They also have a nice list of extensions they support. You need to be a little careful with gcc
and extensions because just specifying which standard you want to use is not enough to generate a warning or error when you are using an extension. For example you might be surprised that using:
gcc -std=c90 -W -Wall
allows you to use variable length arrays without a warning. In order to generate a warning you need to add -pedantic
:
gcc -std=c90 -W -Wall -pedantic
and then this will generate a warning similar to this:
warning: ISO C90 forbids variable length array ‘array’ [-Wvla]
Upvotes: 1
Reputation: 129524
If you want something that compiles with "any" compiler, you should avoid the gnu99
setting, and use the c89
, c99
or c11
- and for C++ use c++03
or c++11
(or c++0x
depending on which particular version of compiler it is). The later you go on these things, the more you restrict to "new versions of compilers".
The gnu99
means C99 with "GNU extensions", which means that code that compiles with this setting may not compile on other compilers.
You should definitely also apply -Wall
, and I like to have -Wextra -Werror
too. -Wall
means enable (almost) all warnings, -Wextra
means enable extra warnings beyond the ones in -Wall
, and -Werror
means that you HAVE to fix any warnings before you get any code ("treat warnings as errors").
Upvotes: 3
Reputation: 122493
Most of C99 feature has been supported by gcc, for detail see Status of C99 features in GCC.
Some GNU extensions are handy to use. Whether choosing between C99 and GNU99 depends on if you are going to use other compilers. But if you are thinking about Visual Studio, it doesn't support C99, so sticking to C89 is the choice if you are going back to Visual Studio later.
Upvotes: 1