Nishant
Nishant

Reputation: 2619

In which version of C was _Bool type introduced?

Answers to this question on SO specify that _Bool was introduced in C99 (specifically BobbyShaftoe's answer).

But the following code compiles perfectly with gcc -std=c90 -pedantic test.c and gcc -std=c89 -pedantic test.c both, producing output 1 (my gcc version is 4.7.1)

#include<stdio.h>
#include<stdlib.h>

int main(){

    _Bool a = 0;
    printf("%u\n",sizeof(a) );
    return 0;
}

So in which version was _Bool introduced ?

Upvotes: 2

Views: 719

Answers (1)

Grzegorz Szpetkowski
Grzegorz Szpetkowski

Reputation: 37914

As pointed by @0xC0000022L you need to differentiate between standard and actual implementation. Interestingly there is however some inconsistency how GCC (and Clang as well) treats _Bool. C99 introduced also _Complex type, for which there is diagnostic message:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    printf("%lu\n", (unsigned long) (sizeof(_Complex)));
    return 0;
}

results into (GCC 4.4.7):

$ gcc -ansi -pedantic-errors check.c 
check.c: In function ‘main’:
check.c:5: error: ISO C90 does not support complex types
check.c:5: error: ISO C does not support plain ‘complex’ meaning ‘double complex’

You may examine source code, and then you will find that indeed _Complex type is checked against standard version, while _Bool is not:

gcc/po/gcc.pot:19940

#: c-decl.c:7366
#, gcc-internal-format
msgid "ISO C90 does not support complex types"
msgstr ""

gcc/c-decl.c:7380

case RID_COMPLEX:
  dupe = specs->complex_p;
  if (!flag_isoc99 && !in_system_header)
pedwarn (input_location, OPT_pedantic, "ISO C90 does not support complex types");

I wouldn't call it a bug, but rather a decision that was made by developers.

Upvotes: 2

Related Questions