Home > Backend Development > C++ > body text

What are the optimal compiler warning levels for different C/C compilers?

Mary-Kate Olsen
Release: 2024-11-02 22:34:30
Original
1024 people have browsed it

What are the optimal compiler warning levels for different C/C   compilers?

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:

  • -xtype
  • -xtype=boundcheck
  • -xtype=fullbounds
  • -xtypespace=follow
  • -xtype=uninitialized

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template