C++ Logo

std-proposals

Advanced search

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

From: David Brown <david.brown_at_[hidden]>
Date: Wed, 25 Nov 2026 10:12:41 +0100
On 24/11/2026 20:44, Andrey Semashev via Std-Proposals wrote:
> On 24 Nov 2026 11:26, David Brown wrote:
>>
>> On 23/11/2026 22:44, Andrey Semashev via Std-Proposals wrote:
>>>
>>> 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++.
>
> I know this, and I realize they standardized the feature the way they
> did in an attempt to not break users' code.
>
> I still think they should have bit the bullet and standardized the type
> as proper keywords. They did that eventually anyway in C23, but now they
> have to maintain stdbool.h for backward compatibility. And there is
> probably a large amount of code that uses that header.

Sure, there still has to be a <stdbool.h>. But we already have it.
Maintenance effort is as near to zero as it could be - and is vastly
smaller than the effort of removing it from toolchains, standards and
documents. This is the entirety of the <stdbool.h> in a typical gcc
toolchain (skipping the copyright message that is bigger than the code) :

#ifndef _STDBOOL_H
#define _STDBOOL_H

#ifndef __cplusplus

#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
/* bool, true and false are keywords. */
#else
#define bool _Bool
#define true 1
#define false 0
#endif

#else /* __cplusplus */

/* Supporting _Bool in C++ is a GCC extension. */
#define _Bool bool

#endif /* __cplusplus */

/* Signal that all the definitions are present. */
#define __bool_true_false_are_defined 1

#endif /* stdbool.h */


Removing it from the C and/or C++ standards would mean that every piece
of code that aims to be widely portable and that is intended to work
with different standards (and for headers, work with both C and C++) now
needs a block of preprocessor gunge to figure out if <stdbool.h> should
be included or not. Or more likely, projects would make their own
"proj_bool.h" header that contained that gunge once, and we are back to
every project doing this in their own way, back to the very problem
_Bool and <stdbool.h> solved in C99.


There's nothing wrong with marking use of <stdbool.h> as an "obsolescent
feature" - that it, it is a feature that exists only for backwards
compatibility and its use is discouraged for new code. Calling it
"deprecated" /would/ be wrong, because it is still often essential and
some coding standards do not allow use of deprecated features without
some kind of "rule exception" documentation.


I do appreciate your "bit the bullet" comment - but it's from hindsight.
  There are countless things in C and C++ where we could say we'd have a
better language today if only the language designers had been braver,
smarter, or had more foresight three or four decades ago. Clearly it
would have been better (to pick a different example) to remove the need
for "break" in switch statements and instead add an explicit
"fallthrough" keyword back when C was first standardised. That would
cause issues with some existing code at the time, but avoid huge numbers
of bugs that came later when many orders of magnitude more C and C++
code was written. Languages always have to evolve from where they are,
and are never "perfect" - I am sure you have noticed!

All we can do now is look at how things could or should be changed going
forward, and occasionally vent our frustrations that the language
designers and committees didn't make better decisions long ago. Then
every now and again someone will try to create "C++++" (or "D", "Cpp2",
"Carbon", "Rust", etc.) that accepts more or less complete breaks in
compatibility and tries to get the language "right". Mostly the result
is only "right" from the point of view of a few people - we all know
that C and C++ are full of serious unfixable flaws, but everyone has
their own opinions on what those are and how to replace them.


>
>> It's easy to use 20/20 hindsight to say that C should have had "bool"
>> from the start.
>
> Maybe not from the start. But by the time C99 came out, bool has been a
> thing in C++ for a long time, and it was clear it is a useful and widely
> adopted concept.

Agreed.

I personally would have been happy if bool, true and false had been made
keywords in C99. But lots of existing, important code - and therefore
lots of other people - would not have been happy. Maybe it would have
been practical to introduce a concept of "overrideable keywords" - make
them act as keywords but allow "typedef enum { false, true } bool;" (or
whatever defines, constants, etc.) to override the names. I think that
would have made fewer people unhappy than normal keywords would, but it
would have added new complications to the language.

>
>> 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" ?
>
> Which is another reason to use a keyword for bool.
>

That would not have avoided the problem. As long as people want to mix
code written to standard X and code written to standard Y, making the
same code have different semantics in X and Y will cause issues.

>> 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).
>
> To be fair, at least some C++ compiler vendors are rather eager to
> remove deprecated features. For example, std::auto_ptr, std::iterator
> are effectively gone.
>

Deprecated features cannot be removed from compliant toolchains
(compilers and/or standard libraries, whichever is relevant). A
deprecated feature is still a feature of the language. The toolchain
can generate warnings on their usage, but they still need to be there.
Only once the feature is removed from the standard (typically a
standards version or two after deprecation) can they be removed from the
toolchain. And even there, toolchains generally do keep them. Try to
use std::auto_ptr with gcc and you'll find it is still there, and still
works, but generates a "deprecated" warning unless you specifically
choose "-std=c++98" - then no working is generated. (std::iterator is
handled similarly.) Individual toolchains may vary, of course.

The only features that are typically removed from toolchains are those
that are /removed/ from the standards, not /deprecated/, and which are
very rarely seen in real code. An example of that would be the "garbage
collector support" parts of <memory>, such as std::declare_reachable.
Even there, toolchains support them for older standards - they are not
removed from the libraries.

Received on 2026-11-25 09:12:49