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

2019-01-04 07:03发布

This note says:

-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.

First things first:

  • What is the purpose of the -pedantic and -ansi options of the GCC/G++ compiler (I couldn't understand the above description)?
  • Can anyone tell me the right circumstances for using these two options?
  • When should I use them?
  • Are they important?

标签: c++ c gcc g++
8条回答
forever°为你锁心
2楼-- · 2019-01-04 07:56

If you're writing code that you envisage is going to be compiled on a wide variety of platforms, with a number of different compilers, then using these flags yourself will help to ensure you don't produce code that only compiles under GCC.

查看更多
男人必须洒脱
3楼-- · 2019-01-04 08:03

If your code needs to be portable then you can test that it compiles without any gcc extensions or other non-standard features. If your code compiles with -pedantic -ansi then in theory it should compile OK with any other ANSI standard compiler.

查看更多
登录 后发表回答