How to find my current compiler's standard, like if it is C90, etc

前端 未结 5 1729
梦谈多话
梦谈多话 2020-12-13 09:29

I\'m working on a Linux machine. Is there any system command to find the standard followed by the C compiler I\'m using?

5条回答
  •  佛祖请我去吃肉
    2020-12-13 09:58

    You can also test this in your code using standard macros, for example (originally from sourceforge project of the same name):

    #if defined(__STDC__)
    # define PREDEF_STANDARD_C_1989
    # if defined(__STDC_VERSION__)
    #  define PREDEF_STANDARD_C_1990
    #  if (__STDC_VERSION__ >= 199409L)
    #   define PREDEF_STANDARD_C_1994
    #  endif
    #  if (__STDC_VERSION__ >= 199901L)
    #   define PREDEF_STANDARD_C_1999
    #  endif
    #  if (__STDC_VERSION__ >= 201710L)
    #   define PREDEF_STANDARD_C_2018
    #  endif
    # endif
    #endif
    

    If you want to check this from the command line you can pick one (e.g. c89) and check the return value from a minimal program:

    echo -e "#ifdef __STDC__\n#error\n#endif"|gcc -xc -c - > /dev/null 2>&1; test $? -eq 0  || echo "c89
    

提交回复
热议问题