Re: About -lm switch used for linking math.h



On 2012-01-28, Keith Thompson <kst-u@xxxxxxx> wrote:
Keith Thompson <kst-u@xxxxxxx> writes:
Stephen Sprunk <stephen@xxxxxxxxxx> writes:
[...]
"_Bool" is a hack around the fact there is no way to introduce a new
basic type in a header file. "bool" is what the standard was really
trying to introduce, but that is a typedef to "_Bool" that one gets by
including <stdbool.h>.

"bool" is a macro, not a typedef (I'm not sure why).

Now that I think about it

bool is not a macro that just expands to any old type name, but one that
expands to a new C language keyword (that names a type).

Because it expands to a C language keyword, the following is a syntax
error:

{
typedef int bool; /* error */
typedef int while; /* exactly like this one */

}

I.e. bool really behaves like a reserved keyword, except that you can #undef it
to make it go away.

Making it a typedef would be a small consolation prize, given that true and
false cannot be similarly made into first-class language features. The whole
pack of three might as well be macros.

, it's probably so you can do something like
this for legacy code that defines "bool", "true", and/or "false":

Legacy code that defines bool, true and false will not #include <stdboo.h>.
Some legacy code also defines uint32_t, etc. So what?

Either fix the legacy code, or don't compile it as C99 and don't include new
headers.

You can't undefine a typedef.

If this is a disadvantage of typedef, why not replace all standard typedefs
with macros?

They could just have added "untypedef" to the language, by the way.
Compared to some of the arcane inventions, that's trivial.

Note that just not having "#include <stdbool.h>" is not a complete
solution; it might be included indirectly.

<inttypes.h> could be included indirectly too. So let's make all types like
uint32_t into macros.
.



Relevant Pages

  • 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: 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)
  • 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: [RFC][PATCH] A generic boolean (version 3)
    ... Define a Boolean data type. ... +typedef bool boolean; ... +#undef false ...
    (Linux-Kernel)
  • Re: Boolean data type?
    ... What type is commonly used in C for playing around with boolean ... If you have C99 {where _Bool is a type} then: ... The header defines four macros. ... which expands to the integer constant 1, ...
    (comp.lang.c)