Tuesday, July 28, 2009

bool & GCC

Abstract: I'll try to clear up confusion about bool for non-compiler people;)

Even some of my teammate on compiler would misunderstand bool with GCC some times. So I'm trying to make it a bit clear:

bool is not an valid type in C89, which is referred as ANSI C sometimes. Therefore, if you are working on a project that is supposed to be compiled with an ANSI C compiler, do not use bool type. However, bool is valid in C99 as _Bool, so you can use it safely if your code is not expected to be compiled with an ancient compiler;)

In GCC code, you can see 'bool' here and there, but bear in mind that it's fake - it's actually unsigned char, defined in gcc/system.h. This is because GCC is expected to bootstrap with an ANSI C compiler.

In C++, bool is always valid, you don't have to worry about bool.

No comments:

Post a Comment