Posts Tagged ‘C11’

Was a C90, C99, or C11 compiler used?

January 2nd, 2018 2 comments

How can a program figure out whether it has been compiled with a C90, C99 or C11 compiler?

Support for the // style of commenting was added in C99.

Support for Unicode string literals (e.g., U"Hello World") was added in C11.

Putting these together we get the following:

#include <stdio.h>
#define M(U) sizeof(U"s"[0])
int main(void)
    switch(M("")*2 //**/ 2
       case 1: printf("C90\n"); break;
       case 2: printf("C99\n"); break;
       case 8: printf("C11\n"); break;
Tags: , ,