How to get current c dialect in gcc?

為{幸葍}努か 提交于 2019-12-24 05:27:13

问题


Newbie in C programming.
In gcc -std sets the C standard that compiles, e.g. gcc -std=c99.
It's possible to know which C standard is currently set?


回答1:


You can use this program to print the default:

#include <stdio.h>

int main() {
#ifdef __STRICT_ANSI__
    printf("c");
#else
    printf("gnu");
#endif

#ifdef __STDC_VERSION__
  #if __STDC_VERSION__ == 199901L
    puts("99");
  #elif __STDC_VERSION__ == 201112L
    puts("11");
  #else
    puts("(unknown)");
  #endif
#else
  puts("90");
#endif
  return 0;
}



回答2:


There are various preprocessor symbols that are defined in various modes. You can use gcc -E -dM -x c /dev/null to get a dump of all the preprocessor symbols that are predefined.

When in C99 mode (-std=c99 or -std=gnu99), the symbol __STDC_VERSION__ is defined to be 199901L. In C11 mode (with -std=c11 or std=gnu11), it's 201112L

When in strict C mode (-std=cXX as opposed to -std=gnuXX), the symbol __STRICT_ANSI__ is defined to be 1



来源:https://stackoverflow.com/questions/22949060/how-to-get-current-c-dialect-in-gcc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!