-ansi turns off some extensions of GCC whereas -pedantic turns off more extensions. It seems like -ansi is first level rule then -pedantic is more restricted rule. Does it mean with this two options remove I can have my code more compatible to other compiler like Microsoft one?
@huahsin68: well, more or less. MSVC is a rather different compiler from most others, more adapted to its particular ecosystem and not available outside it. It does a lot of things its own way - which is not the same as the standard. Nevertheless, if you stay with the standard headers and so on, then MSVC and GCC are fairly similar. However, using -std=c89 -pedantic does mean you can move more easily between different compilers on other platforms. As soon as you start using <windows.h>, compatibility with other systems becomes problematic.
@slf: Because like every other vendor (albeit that GNU doesn't sell their compiler for cash), they would like you to use their proprietary features? Or, more generally, because they consider the extensions useful and think they should be enabled by default.
For whatever it is worth, and JFTR, I've mostly stopped using -pedantic, but most of my code still compiles OK when I re-enable it (the one program that didn't was explicitly using __int128 types, which are pedantically incorrect). I think there was an intervening stage when GCC was too noisy (for my liking) with -pedantic. I just tested about 300 source files some library code, some commands, some SO test programs and there was just the one to-be-expected problem. Currently using GCC 4.8.2 on Mac OS X 10.9.2.
The -ansi flag is equivalent to -std=c89. As noted, it turns off some extensions of GCC. Adding -pedantic turns off more extensions and generates more warnings. For example, if you have a string literal longer than 509 characters, then -pedantic warns about that because it exceeds the minimum limit required by the C89 standard. That is, every C89 compiler must accept strings of length 509; they are permitted to accept longer, but if you are being pedantic, it is not portable to use longer strings, even though a compiler is permitted to accept longer strings and, without the pedantic warnings, GCC will accept them too.
Why is this not defaulted to true? Why have to opt-in for it rather than opt-out?