Re: short circuit evaluation



CBFalconer <cbfalconer@xxxxxxxxx> writes:
Keith Thompson wrote:
CBFalconer <cbfalconer@xxxxxxxxx> writes:
James Kuyper wrote:

... snip about <stdbool.h> ...

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.

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

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.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <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"
.



Relevant Pages

  • Re: short circuit evaluation
    ... But I mis-remembered it as a standard ... typedef because it makes more sense to me that it would be a ... Does anyone know why it's a macro? ... making 'bool' a macro allows you do so. ...
    (comp.lang.c)
  • Re: short circuit evaluation
    ... typedef because it makes more sense to me that it would be a ... Does anyone know why it's a macro? ... making 'bool' a macro allows you do so. ... Because 'bool' was not a reserved word in C90. ...
    (comp.lang.c)
  • Re: short circuit evaluation
    ... typedef because it makes more sense to me that it would be a ... Does anyone know why it's a macro? ... making 'bool' a macro allows you do so. ... keep the compiler compatible with C90 source that used it, ...
    (comp.lang.c)
  • Re: short circuit evaluation
    ... But I mis-remembered it as a standard ... typedef because it makes more sense to me that it would be a ... Does anyone know why it's a macro? ... making 'bool' a macro allows you do so. ...
    (comp.lang.c)
  • Re: Absense of bool
    ... but that's easily achieved by a programmer-defined typedef or even by ... typedef enum bool; ... glad C99 added it. ... (I personally wouldn't provide implicit conversions to ...
    (comp.lang.c)