How to find out which ANSI C standard my gcc works with by default?

后端 未结 4 706
無奈伤痛
無奈伤痛 2020-12-19 06:49

I read here it is C90 with extensions. How can I know for sure?

相关标签:
4条回答
  • 2020-12-19 07:30

    You can also check one of the predefined Macros, for example whether your GCC asks for ANSI C (STRICT__ANSI) by default (i.e. without any cli arguments).

    0 讨论(0)
  • 2020-12-19 07:31

    Use the -std= flag to specify a language dialect: c89, c99, c++98, etc. Note that c90 is equivalent to c89.

    As a shorthand -ansi causes -std=c89 in C mode and -std=c++98 in C++ mode.

    Use -pedantic to enable all diagnostics that the standards require.

    The defaults are gnu89 for C and gnu++98 for C++. Consult the manual for detailed descriptions of the various dialects.

    0 讨论(0)
  • 2020-12-19 07:31

    Read the manpage. On my computer (OSX 10.7, gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)):

    -std=
            Determine the language standard. This option is currently only supported
            when compiling C or C++.

            A value for this option must be provided; possible values are

    ....

            gnu89
                    Default, ISO C90 plus GNU extensions (including some C99 features).

    ....

            gnu++98
                    The same as -std=c++98 plus GNU extensions. This is the default for C++ code.

    0 讨论(0)
  • 2020-12-19 07:32

    Try below command and search for std

    gcc -v --help | less
    

    It will show you all the available options for your gcc.

    0 讨论(0)
提交回复
热议问题