'How can I know the version of c?

The "\b" didn't work on my Mac. So I tried to find the reason.

I think that cause of this problem may be the version of C.

Or device could be. If you know it, can you help me? Thank you.

c


Solution 1:[1]

There are three ISO standard versions of C: C90, C99 and C11. To know which C version your program is running check the:

 __STDC_VERSION__

macro.

  • For C90: the macro is undefined.
  • For C99: the macro is defined with value 199901L.
  • For C11: the macro is defined with value 201112L.

On the other hand if what you want to know is the version not of C but the version of your C compiler, as the other answers suggests, run the compiler with the appropriate option (--version for both gcc and clang for example).

Depending on your compiler it can support different C versions. You can ask to change the compiler default C version used for compiling using the -std= option with gcc and clang, for example: -std=c90, -std=c99 or -std=c11.

Solution 2:[2]

Prerequisites: gcc should be installed.

You open your terminal and paste this bash command:

gcc -dM -E - < /dev/null | grep __STDC_VERSION__ | awk '{ print $2 " --> " $3 }'

For my case it returns __STDC_VERSION__ --> 201710L which translates to the 2017 C standard(c17). Yours can be c89 or c99 or c11

Solution 3:[3]

int main()
{

    if (__STDC_VERSION__ >= 201710L)
        printf("We are using C18!\n");
    else if (__STDC_VERSION__ >= 201112L)
        printf("We are using C11!\n");
    else if (__STDC_VERSION__ >= 199901L)
        printf("We are using C99!\n");
    else
        printf("We are using C89/C90!\n");

    return 0;
}

Solution 4:[4]

based on what @chqrlie added...

#include <stdio.h>

int main() {
  #if defined __STDC_VERSION__ 
    long version = __STDC_VERSION__;
    if ( version == 199901 ) {
      printf ("version detected : C99\n");
    }
    if ( version == 201112 ) {
      printf ("version detected : C11\n");
    }
    if ( version == 201710 ) {
      printf ("version detected : C18\n");
    }
  #else 
    printf ("version detected : C90\n");
  #endif
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 winterr_dog
Solution 3 Obsidian
Solution 4 mtraceur