Submitter:Fred J. Tydeman
Submission Date: 2021-04-18
Document: WG14 N2712
Title: N2712: intbool_t
Reference Documents:N2596

Summary

When C was created, there was no boolean type, so int was used. Now that bool is part of C, perhaps we should change the return type of some functions. These would be functions that return success (non-zero) and failure (zero) as true / false.

7.4.1 Character classification functions, paragraph 1 has:

The functions in this subclause return nonzero (true) if and only if the value of the argument c conforms to that in the description of the function.

7.30.2.1 Wide character classification functions, paragraph 1 has:

The functions in this subclause return nonzero (true) if and only if the value of the argument wc conforms to that in the description of the function.

Proposal

Define

typedef int intbool_t;

as the new return type of several functions.

ctype.h:
isalnum() isalpha() isblank() iscntrl() isdigit() isgraph() islower() isprint() ispunct() isspace() isupper() isxdigit()

math.h
iscanonical() isfinite() isinf() isnan() isnormal() signbit() issignaling() issubnormal() iszero() samequantumdN() isgreater() isgreaterequal() isless() islessequal() islessgreater() isunordered() iseqsig()

threads.h
thrd_equal()

wctype.h
iswalnum() iswalpha() iswblank() iswcntrl() iswdigit() iswgraph() iswlower() iswprint() iswpunct() iswspace() iswupper() iswxdigit() iswctype()

Doing the above has no semantic change as the functions still return an int with the same meaning.

If the above idea is accepted, we need to decide whereall the new typedef is defined.

Independent of the above, it seems that all new functions being added to C23 (and beyond) should use bool instead of int as the success / failure type.

Possible future directions (NOT being proposed for C23)