1

I can choose to call

gcc --std=c99 toto.c -o toto.elf

But in my case, I would like to know which --std is used by default when calling

gcc toto.c -o toto.elf

Note for closing request: I refute the idea that this topic is a duplicate, in fact, what I want is not only knowing what the default --std is but also what --std is currently used and how make difference between std=gnu11 and std=c11. Sure that my first post was leading people in error.

Guillaume D
  • 2,202
  • 2
  • 10
  • 37
  • Does this answer your question? [What is the default C -std standard version for the current GCC (especially on Ubuntu)?](https://stackoverflow.com/questions/14737104/what-is-the-default-c-std-standard-version-for-the-current-gcc-especially-on-u) – costaparas Jan 13 '21 at 14:09
  • You can find manuals for all released GCC version lines at [the GCC docs site](https://gcc.gnu.org/onlinedocs/). Each one documents the default dialect among the arguments accepted for the `--std` option. – John Bollinger Jan 13 '21 at 14:46

2 Answers2

3

i found this gcc -dM -E - < /dev/null | grep 'STDC_VERSION'

Guillaume D
  • 2,202
  • 2
  • 10
  • 37
  • the issue with this solution, is that it doesn't make a difference between ```--std=gnu11``` and ```--std=c11```. Both give ```#define __STDC_VERSION__ 201112L``` – Guillaume D Jan 15 '21 at 10:36
  • 1
    You may fix that with like `gcc -std=c11 -dM -E - < /dev/null | grep 'STDC_VERSION\|__STRICT_ANSI__'`. `__STRICT_ANSI__` will be defined in non-gnu mode. Also, `gcc -std=c89` will not output `STDC_VERSION` - so when it's missing, it's c89 (or older??). – KamilCuk Jan 15 '21 at 10:49
2
  • Everything prior version 5.0.0 has -std=gnu90 as default.
  • Everything between version 5.0.0 and 8.0.0 has -std=gnu11 as default.
  • Everything past 8.0.0 has -std=gnu17 as default.

So you only need to check --version. However, the __STDC_VERSION__ should also correspond to the -std=cxx even when compiling with GNU extensions.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • 1
    According to [its docs](https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/C-Dialect-Options.html#C-Dialect-Options), GCC 10 defaults to `--std=gnu17`. Versions 8 and 9, too. – John Bollinger Jan 13 '21 at 14:42
  • @JohnBollinger Yikes, I'm not up to date then! Thanks. – Lundin Jan 13 '21 at 14:43