Optimal Compiler Warning Level for C/C
Various C/C compilers offer different warning levels, influencing the amount and severity of warnings reported during compilation. Here are some recommended warning levels for different compilers:
GCC/G :
For GCC and G , the recommended level is '-Wall'. This enables all warnings that the compiler deems relevant to potential errors or poor coding practices.
Sun CC:
For Sun CC, '-xlist=custom' is recommended, with the following warning flags:
aCC (HPUX):
For aCC, '-qwarn all=on2' is advised. This enables all available warnings, including the highest severity level.
Visual Studio:
For Visual Studio, '/W4' is recommended. This setting enables all warnings except those that are considered by the compiler to be too noisy or potentially confusing.
Intel:
For Intel C/C compilers, '-Wall' is a good starting point. Additional specific warnings can be enabled as needed, such as '-Wselect-any-enum-values' or '-Wno-unused-value'.
GCC/G Extra-Paranoid Flags:
For extreme vigilance, the following set of flags can be used in addition to '-Wall':
-Weffc++ -pedantic -pedantic-errors -Wextra -Waggregate-return -Wcast-align \ -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion \ -Wdisabled-optimization \ -Werror -Wfloat-equal -Wformat -Wformat=2 \ -Wformat-nonliteral -Wformat-security \ -Wformat-y2k \ -Wimplicit -Wimport -Winit-self -Winline \ -Winvalid-pch \ -Wunsafe-loop-optimizations -Wlong-long -Wmissing-braces \ -Wmissing-field-initializers -Wmissing-format-attribute \ -Wmissing-include-dirs -Wmissing-noreturn \ -Wpacked -Wpadded -Wparentheses -Wpointer-arith \ -Wredundant-decls -Wreturn-type \ -Wsequence-point -Wshadow -Wsign-compare -Wstack-protector \ -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch -Wswitch-default \ -Wswitch-enum -Wtrigraphs -Wuninitialized \ -Wunknown-pragmas -Wunreachable-code -Wunused \ -Wunused-function -Wunused-label -Wunused-parameter \ -Wunused-value -Wunused-variable -Wvariadic-macros \ -Wvolatile-register-var -Wwrite-strings
The above is the detailed content of What are the optimal compiler warning levels for different C/C compilers?. For more information, please follow other related articles on the PHP Chinese website!