Search code examples
cgccdialect

How to get current c dialect in gcc?


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?


Solution

  • 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;
    }