Search code examples
gccc89

Why does GCC not complain about _Bool in c89 mode?


Why does the following command produce no warnings or errors, even though _Bool is not part of C89?

  $ echo "_Bool x;" | gcc -x c -c -std=c89 -pedantic -Wall -Wextra -

For comparison, changing _Bool to bool results in an error:

  $ echo "bool x;" | gcc -x c -c -std=c89 -pedantic -Wall -Wextra -
  <stdin>:1:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘x’

This happens on Cygwin [gcc (GCC) 4.5.3] and Linux [gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)].


Solution

  • Using _Bool in a C89 compiler invokes undefined behavior because you use an identifier starting with an underscore and upper case letter. I don't have the paper copy of C89 handy, but expect it to be the same as C99 7.1.3:

    — All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.

    One permissible undefined behavior is accepting _Bool without a diagnostic. This is a GNU extension.

    Of course, bool doesn't fall into the implementation namespace, so must be diagnosed unless declared.