short circuit evaluation

J

James Kuyper

It is actually a macro, it's explicity mentioned in the standard to be
so.
See 7.16 p 2

You're right - my mistake. But I mis-remembered it as a standard typedef
because it makes more sense to me that it would be a typedef. Does
anyone know why it's a macro? I suppose it might be because you can
#undef a macro, but you can't turn off a typedef. If you want to use
'bool' as the standard macro in one part of a translation unit, and as a
user-defined identifier with an incompatible meaning from legacy code in
a later part of the same translation unit, making 'bool' a macro allows
you do so. But that seems like too convoluted a motivation for such a
choice.
 
C

CBFalconer

.... snip about said:
You're right - my mistake. But I mis-remembered it as a standard
typedef because it makes more sense to me that it would be a
typedef. Does anyone know why it's a macro? I suppose it might be
because you can #undef a macro, but you can't turn off a typedef.
If you want to use 'bool' as the standard macro in one part of a
translation unit, and as a user-defined identifier with an
incompatible meaning from legacy code in a later part of the same
translation unit, making 'bool' a macro allows you do so. But
that seems like too convoluted a motivation for such a choice.

Because 'bool' was not a reserved word in C90. This way you can
keep the compiler compatible with C90 source that used it, and true
and false macros, differently. Note that _Bool IS a reserved word,
but is in the implementors namespace.
 
K

Keith Thompson

CBFalconer said:
Because 'bool' was not a reserved word in C90. This way you can
keep the compiler compatible with C90 source that used it, and true
and false macros, differently. Note that _Bool IS a reserved word,
but is in the implementors namespace.

The question is why 'bool' is a macro rather than a typedef, not why
it's not a keyword in C99.
 
J

James Kuyper

CBFalconer said:
James Kuyper wrote:


Because 'bool' was not a reserved word in C90. This way you can
keep the compiler compatible with C90 source that used it, and true
and false macros, differently. Note that _Bool IS a reserved word,
but is in the implementors namespace.

How would making bool a typedef that is defined in stdbool.h cause a
problem for the compiler? Standard typedefs (like size_t) aren't
keywords, any more than standard macros are.
 
C

CBFalconer

James said:
How would making bool a typedef that is defined in stdbool.h cause a
problem for the compiler? Standard typedefs (like size_t) aren't
keywords, any more than standard macros are.

Consider a source for C90 that defines bool, true, and false. If
C99 made those words reserved, the C90 source could not be compiled
on a C99 compiler (barring identical definitions). However, simply
failing to #include <stdbool.h> avoids the whole problem. This is
fairly automatic, since <stdbool.h> didn't exist in C90.
 
K

Keith Thompson

CBFalconer said:
Which is what I thought I said.

Um, no.

Your statement "Because 'bool' was not a reserved word in C90" is a
valid answer to "Why is 'bool' not a reserved word in C99?", but
nobody asked that question.

*Either* making bool a macro *or* making it a typedef would avoid any
problems with C90 code that uses the name "bool" as an identifier;
such code wouldn't include <stdbool.h>, so the macro or typedef would
not be visible.

The question under discussion was: Why is bool a macro rather than a
typedef in C99? Nothing you've said addresses that question.
 
J

James Kuyper

CBFalconer said:
Which is what I thought I said.

No, you explained why it isn't a keyword. Since defining bool as a macro
or as a typedef would be equally effective at avoid the problem that
would occur if it were defined as a keyword, your answer says nothing
about why a macro was chosen, rather than a typedef. Since my question
was about why a macro was chosen, rather than a typedef; since my
question did not involve keywords in any way, shape, or form, your
answer was completely irrelevant to my question.
 
J

James Kuyper

CBFalconer said:
Consider a source for C90 that defines bool, true, and false. If
C99 made those words reserved, ...

I wasn't asking about why C99 didn't make bool a reserved word. I was
asking why C99 didn't make it a typedef, like size_t.
... the C90 source could not be compiled
on a C99 compiler (barring identical definitions). However, simply
failing to #include <stdbool.h> avoids the whole problem. This is
fairly automatic, since <stdbool.h> didn't exist in C90.

What does that have to do with whether bool should have been a macro or
a typedef? What you've said is equally true either way.
 
L

lawrence.jones

Keith Thompson said:
Oddly, I can't find this change either in any of the Technical
Corrigenda or in any of the Defect Reports.

Caution: Editor at work :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top