There are many places within the API that should use a boolean type but currently use int.
The docs even talk about TRUE and FALSE, hence I would like a proper boolean type for clarity.
Suggested ideas:
Use <stdbool.h> which would give us bool, true, and false as native types
Define our own uiBool or _UI_BOOL and use TRUE and FALSE (which seem to be defined in glib, the win32 API and Objective-C?)
A mix of both <stdbool.h> to get true and false for use internally and our own uiBool or _UI_BOOL type to expose in the pulic API.
C99 interop with C++ seems to be a non issue, otherwise no software would work anywhere.
So unless I'm missing something the only concern would be ABI stability:
From the C99 standard:
An object declared as type _Bool is large enough to store the values 0 and 1.
Essentially meaning bool is implementation defined. In practice each arch seems to define sizeof(bool) to prevent havoc (similar to how each arch defines int?).
On x86_64 all compilers I checked (gcc, clang, tcc, icc, zig cc, g++, clang++) define it as 1, which makes sense, because otherwise the entire shared library system on unix platforms would not work.
I am fairly certain using option 1 and exposing bool in the public API would not be breaking ABI. So my vote would be option 1, nice and clean, using compiler native types.
If this is deemed to risky we could define our own uiBool type: #define uiBool int
Then we could redefine uiBool to be bool in doxygen to make the intent clear.
In this case I would like to see a build flag -Dforce-stable-abi=(true|false) which would default to true.
For true this would define uiBool int, _UI_ENUM int
For false this would define uiBool bool, _UI_ENUM enum to get actual type correctness.
I currently build everything in tree, hence I care more about type hints by the compiler than ABI. For shared library distribution, I am definitely for ensuring ABI compatibility. From what I can tell exposing bool would not pose a problem though.
There are many places within the API that should use a boolean type but currently use
int
. The docs even talk aboutTRUE
andFALSE
, hence I would like a proper boolean type for clarity.Suggested ideas:
<stdbool.h>
which would give usbool
,true
, andfalse
as native typesuiBool
or_UI_BOOL
and useTRUE
andFALSE
(which seem to be defined in glib, the win32 API and Objective-C?)<stdbool.h>
to gettrue
andfalse
for use internally and our ownuiBool
or_UI_BOOL
type to expose in the pulic API.C99 interop with C++ seems to be a non issue, otherwise no software would work anywhere.
So unless I'm missing something the only concern would be ABI stability:
From the C99 standard:
Essentially meaning
bool
is implementation defined. In practice each arch seems to definesizeof(bool)
to prevent havoc (similar to how each arch definesint
?). Onx86_64
all compilers I checked (gcc, clang, tcc, icc, zig cc, g++, clang++) define it as1
, which makes sense, because otherwise the entire shared library system on unix platforms would not work.I am fairly certain using option 1 and exposing
bool
in the public API would not be breaking ABI. So my vote would be option 1, nice and clean, using compiler native types.If this is deemed to risky we could define our own
uiBool
type:#define uiBool int
Then we could redefineuiBool
to bebool
in doxygen to make the intent clear. In this case I would like to see a build flag-Dforce-stable-abi=(true|false)
which would default totrue
. Fortrue
this would defineuiBool int
,_UI_ENUM int
Forfalse
this would defineuiBool bool
,_UI_ENUM enum
to get actual type correctness.I currently build everything in tree, hence I care more about type hints by the compiler than ABI. For shared library distribution, I am definitely for ensuring ABI compatibility. From what I can tell exposing
bool
would not pose a problem though.