How to check if the C compiler standard is C89 C99 C11 or C17 in C

2 Answers

0 votes
#include <stdio.h>

#if !defined(__STDC__)
#   define __STDC__ 0
#endif

#if !defined(__STDC_VERSION__) 
#   define __STDC_VERSION__ 0
#endif


int main()
{
    if (!__STDC__ && !__STDC_VERSION__) {
        printf("The C compiler is not C89 or later standard\n");
    } else if (__STDC_VERSION__ >= 201710L) {
                printf("The C compiler is C17 standard\n");
            } else if (__STDC_VERSION__ >= 201112L) { 
                        printf("The C compiler is C11 standard\n");
                    } else if (__STDC_VERSION__ >= 199901L) {
                                printf("The C compiler is C99 standard\n");
                            } else if (__STDC_VERSION__ >= 199409L) {
                                    printf("The C compiler is amended C90 standard (C95)\n"); 
                                } else if (__STDC__) { 
                                    printf("The C compiler is ANSI C89 / ISO C90 standard\n");
                                }
   
    if (__STDC__) 
        printf("__STDC__: %ld\n", __STDC_VERSION__);
    if (__STDC_VERSION__) 
        printf("__STDC_VERSION__: %ld\n\n", __STDC_VERSION__);

    return 0;
}



  
/*
run:
 
The C compiler is C99 standard
__STDC__: 199901
__STDC_VERSION__: 199901
 
*/

 



answered Apr 20, 2022 by avibootz
edited Apr 21, 2022 by avibootz
0 votes
// Microsoft Visual Studio Community 2022 

#include <stdio.h>

#if !defined(__STDC__)
#   define __STDC__ 0
#endif

#if !defined(__STDC_VERSION__) 
#   define __STDC_VERSION__ 0
#endif


int main()
{
    if (!__STDC__ && !__STDC_VERSION__) {
        printf("The C compiler is not C89 or later standard\n");
    }
    else if (__STDC_VERSION__ >= 201710L) {
        printf("The C compiler is C17 standard\n");
    }
    else if (__STDC_VERSION__ >= 201112L) {
        printf("The C compiler is C11 standard\n");
    }
    else if (__STDC_VERSION__ >= 199901L) {
        printf("The C compiler is C99 standard\n");
    }
    else if (__STDC_VERSION__ >= 199409L) {
        printf("The C compiler is amended C90 standard (C95)\n");
    }
    else if (__STDC__) {
        printf("The C compiler is ANSI C89 / ISO C90 standard\n");
    }

    if (__STDC__)
        printf("__STDC__: %ld\n", __STDC_VERSION__);
    if (__STDC_VERSION__)
        printf("__STDC_VERSION__: %ld\n\n", __STDC_VERSION__);

    return 0;
}




/*
run:

The C compiler is C17 standard
__STDC_VERSION__: 201710

*/

 



answered Apr 20, 2022 by avibootz
edited Apr 21, 2022 by avibootz

Related questions

1 answer 137 views
1 answer 238 views
1 answer 228 views
1 answer 141 views
141 views asked Apr 22, 2022 by avibootz
1 answer 167 views
1 answer 119 views
1 answer 99 views
...