C++ Logo

std-proposals

Advanced search

[std-proposals] Character classification functions should return bool

From: blacktea hamburger <greenteahamburger_at_[hidden]>
Date: Sat, 22 Oct 2022 18:35:59 +0800
WG21's views are not necessarily the same as WG14. It may broke some code,
but it was probably code of the sort that has become increasingly rare over
the years since C++ diverged from C. C and C++ are different languages,
aren't they?

So I think it can be still proposed to WG21.

On Tuesday, October 18, 2022, JeanHeyd Meneide via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> There was a proposal to change this sent to WG14 already, with motivated
reasoning due to in-the-wild code using them wrong:
> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2541.pdf
> The problem is that the wording was extremely intentional for C. People
use the int-based return type to add additional stored information into the
return value, such as classification bits for the given input character
(packed as bit flags in the return value). It was meant to make mixed
table-based, macro-based implementations be fast, back in the day when
compilers were terrible. (And for C, given the wide berth of quality of
implementations, still are too terrible to optimize properly.) Even if you
could overcome ABI arguments ("bool is returned in different registers from
int"), you would need to tell all the implementations using the
implementation-definedness non-zero return value to stop doing that.
>
> While everyone in the room evaluating the proposal understood, ultimately
for many of the stability reasons the proposal was rejected. You'd have
better luck designing new, multi-code-unit encoding (e.g. UTF-8) compatible
character classification functions for C and C++ to get the ball rolling,
killing 2 birds with one stone (can handle variable-encoding data, and have
better return values).
>
> Sincerely,
> JeanHeyd
>
> On Mon, Oct 17, 2022 at 12:59 AM Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:
>>
>> On Sunday, 16 October 2022 03:42:33 PDT blacktea hamburger via
Std-Proposals
>> wrote:
>> > Character classification functions in C return int, but C++ has
built-in
>> > bool type, so they should return bool.
>> >
>> > And they are usually used like:
>> >
>> > if (std::isdigit(c))
>> > { ... }
>> >
>> > So it basically won't break existing code.
>>
>> Those functions are inherited from C and come from a C header, even if
it has
>> a C++ name (cctype). You need to propose this to WG14 first.
>>
>> What possible gain would we have for this change? What is that legacy int
>> hurting?
>>
>> --
>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>> Software Architect - Intel DCAI Cloud Engineering
>>
>>
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-10-22 10:36:02