huahsin68 huahsin68 - 22 days ago 10
C Question

What is the purpose of using -pedantic in GCC/G++ compiler?


-ansi
: tells the compiler to implement the ANSI language option. This turns
off certain "features" of GCC which
are incompatible with the ANSI
standard.

-pedantic
: used in conjunction with
-ansi
, this tells the compiler to be adhere strictly to the ANSI standard,
rejecting any code which is not
compliant.


Text above is extract from this note. First thing first, what is the purpose of usage of
-pedantic
and
-ansi
option with GCC/G++ compiler, I couldn't understand the above description. Can anyone tell me the circumstances of using the above two options? When should I use it? Is it important one?

Answer

GCC compilers always try to compile your program if this is at all possible. However, in some cases, the C and C++ standards specify that certain extensions are forbidden. Conforming compilers such as gcc or g++ must issue a diagnostic when these extensions are encountered. For example, the gcc compiler’s -pedantic option causes gcc to issue warnings in such cases. Using the stricter -pedantic-errors option converts such diagnostic warnings into errors that will cause compilation to fail at such points. Only those non-ISO constructs that are required to be flagged by a conforming compiler will generate warnings or errors.

Comments