Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

undeclared identifier 'bool'

348 views
Skip to first unread message

steve

unread,
Apr 13, 2011, 2:19:48 PM4/13/11
to
Using:
Wedit:[09/16/09]
Lcc: [06/14/10]

I've ignored this error message forever: undeclared identifier 'bool'
and just lived with it, but, I was wondering why LccWin32 has no
'bool' type ?

Antoine Leca

unread,
Apr 14, 2011, 4:39:52 AM4/14/11
to
steve wrote:
> I've ignored this error message forever: undeclared identifier 'bool'
> and just lived with it, but, I was wondering why LccWin32 has no
> 'bool' type ?

Do you #include <stdbool.h> ?


Antoine

jacob navia

unread,
Apr 14, 2011, 8:15:21 AM4/14/11
to
Le 14/04/11 10:39, Antoine Leca a écrit :

Yes, you have to include a file to use a basic type: bool.

The boolean type is called "_Bool" and you can use THAT type
WITHOUT including anything.

Please do not blame me. This is according to the C99 standard
that I implemented.

flames > /dev/C99StandardCommittee


steve

unread,
Apr 14, 2011, 1:53:40 PM4/14/11
to
On Apr 14, 5:15 am, jacob navia <ja...@spamsink.net> wrote:
> Le 14/04/11 10:39, Antoine Leca a écrit :
> > Do you #include<stdbool.h>  ?
>
> > Antoine

> Yes, you have to include a file to use a basic type: bool.
>

> Please do not blame me. This is according to the C99 standard
> that I implemented.


Thanks Antoine and Jacob.
Jacob, no I don't blame you, I always just used BOOL.
Thought it was weird there was no 'bool' type, tho.
Guess I'll start including <stdbool.h> from now on.

Keith Thompson

unread,
Apr 14, 2011, 4:05:09 PM4/14/11
to
jacob navia <ja...@spamsink.net> writes:
> Le 14/04/11 10:39, Antoine Leca a écrit :
>> steve wrote:
>>> I've ignored this error message forever: undeclared identifier 'bool'
>>> and just lived with it, but, I was wondering why LccWin32 has no
>>> 'bool' type ?
>>
>> Do you #include<stdbool.h> ?
>
> Yes, you have to include a file to use a basic type: bool.
>
> The boolean type is called "_Bool" and you can use THAT type
> WITHOUT including anything.
>
> Please do not blame me. This is according to the C99 standard
> that I implemented.
>
> flames > /dev/C99StandardCommittee

In fact, there was a very good reason that the C99 committee didn't
make bool a keyword. There's a fair amount of existing C90 code
that uses bool as an identifier, and making it a keyword would have
broken all that code.

So they did the next best thing: they introduced a new keyword, _Bool,
which is in the reserved namespace (so any code it might break was
non-portable in the first place), and they added a macro definition for
"bool" in a new header. Existing C90 code that declares, for example:

typedef enum bool { false, true };

continues to work without change, and new code that uses the new
predefined type can easily do so by adding

#include <stdbool.h>

And yes, they did introduce some new keywords, namely restrict and
inline. But "restrict" was less likely to be used as an identifier,
and "inline" was used mostly as an extension with a meaning very
similar to what the C99 committee adopted.

(Conceivably they could have made it some kind of non-reserved
keyword, but getting all the corner cases right would have been a
daunting task.)

Certainly if C were being designed from scratch, it would make
sense for bool to be a keyword, just as int and char are keywords,
but the C99 committee didn't have the luxury of doing that.
(Bjarne Stroustrup, when he was designing "C with Classes", which
evolved into C++, decided he did have that luxury, which is why
bool is a keyword in C++.)

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

0 new messages