C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Don't get rid of <stdbool.h>

From: Alejandro Colomar <une+cxx_std-proposals_at_[hidden]>
Date: Mon, 23 Nov 2026 23:02:54 +0100
Hi Andrey,

> Date: 2026-11-24 00:50:14+0300
> From: Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]>
>
> On 24 Nov 2026 00:44, Andrey Semashev wrote:
> > On 24 Nov 2026 00:11, Frederick Virchanza Gotham via Std-Proposals wrote:
> >>
> >> I don't know if there are plans to deprecate <stdbool.h> and
> >> <stdalign.h> now that they have been replaced with keywords in C, but
> >> I'd just like to say that I think that they should be kept forever in
> >> both C and C++, especially because there's such wide variety in what
> >> standards of C are used (some still on C89).
> >>
> >> It's nice to be able to write a header file as follows:
> >>
> >> #include <stdbool.h>
> >> extern bool Init(void);
> >>
> >> instead of having to do:
> >>
> >> #ifndef __cplusplus
> >> # include <stdbool.h>
> >> #endif
> >> extern bool Init(void);
> >>
> >> I think it was a mistake for them to deprecate these headers in C23,
> >> because now we have to do:
> >>
> >> #if !__cplusplus && __STDC_VERSION__ < 202311l
> >> # include <stdbool.h>
> >> #endif
> >> extern bool Init(void);
> >>
> >> I think C should on undeprecate these headers, and I think C++ should
> >> never deprecate them.
> >
> > Just don't include stdbool.h, ever. IMHO, that header is a mistake, not
> > the fact it was deprecated.
>
> Apparently it was not deprecated. This doesn't change my opinion of it,
> just means that it will remain a useless compatibility shim that
> shouldn't have existed in the first place.
>
> > I think, the C's approach to introduce keywords as macros first does
> > more harm than good.

It has some nice side effects: you can test for the existence of the
header (or of the macro) to know whether the feature is available:

 #if __has_include(<stdcountof.h>)
 # include <stdcountof.h>
 #else
 # define countof(a) (sizeof(a) / sizeof((a)[0]))
 #endif

If you only have the keyword, then you need to complicate your build
system.


Have a lovely night!
Alex

> > It should have accepted bool/true/false as keywords
> > from the start. That's what people actually want to write, not the _Bool
> > weirdness that should be fixed into normal bool with a macro defined in
> > a header. If it breaks some code, so be it, let that code be on an older
> > version of the standard and be updated accordingly. But the fact that
> > people defined their own bool types just reinforces my point and shows
> > that C was severely lagging behind.

-- 
<https://www.alejandro-colomar.es>

Received on 2026-11-23 22:03:03