C++ Logo

std-proposals

Advanced search

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

From: David Brown <david.brown_at_[hidden]>
Date: Tue, 24 Nov 2026 09:26:52 +0100
On 23/11/2026 22:44, Andrey Semashev via Std-Proposals 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.
>
> I think, the C's approach to introduce keywords as macros first does
> more harm than good. 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.
>

I would say you have that a little bit backwards. Originally C did not
have a boolean type, because "int" handled the job. The fact that
people made their own "bool" types showed that it was a useful concept,
so it got standardised in C99 along with many other features that people
wanted and compilers had added as extensions, some of them copied across
from C++.

But given that C99 added a boolean type, how could that be handled other
than by using names that did not conflict with commonly used existing
identifiers? They could not simply call the type "bool" and tell
everyone your pre-C99 code is now broken and must be changed. Use of
<stdbool.h> is perhaps not that elegant, but backwards compatibility is
a key reason why C (not C++) forms the backbone and foundation of the
computing world, and is still the single most important programming
language after 50 years.

It's easy to use 20/20 hindsight to say that C should have had "bool"
from the start. Similarly, C++ should have had concepts, reflection,
and modules from day one - copying C's #include system and limited
object file format was obviously a mistake.


The reasonable good way to handle backwards compatibility for a language
that evolves is to have a clear way to specify the language version used
by code. Neither C nor C++ has that. (They've got messy, ugly ways
with preprocessor tests for __STDC_VERSION__, feature test macros, etc.
But not good, simple, clear, standardised method.) And even then you
have complications - what happens when one file uses a C99 bool while
another uses a C90 "typedef int bool" ?

Both C and C++ do their best to figure ways to keep backwards
compatibility while moving the languages forward. <stdbool.h> is part
of that - it was the least bad solution at the time, and is still
included by many cross-language headers today (whether they are compiled
as C or C++). I think we can be entirely confident that C and C++
toolchains will continue to have and support <stdbool.h> for as long as
there are C and C++ compilers, with a total disregard for whatever any
future standards committee says about removing them (not that I think
the standards committees will remove them).

David

Received on 2026-11-24 08:27:01