I was reading the GLFW library and I noticed they use GLFW_TRUE(1) and GLFW_FALSE(0). Now I've already seen that in other frameworks as well,making their own custom true/false identifiers. Is there any reason in creating your own custom true/false enums or classes in a framework? Does it make the code more readable for example? Is it a compatibility issue?
If you plan to use your library in different environments, you can easily get to one that lacks those definitions in a header file. The earliest notable case of this, is when the curses library was developded (there was no <stdbool.h>
yet, not the bool
type defined in the standard library)
In those cases, it would be better to provide one definition yourself, but if you don't want to class with the standard ones, you have to define yours with some prefix that allows you to distinguish your definition from other libraries.
In C, bool
is simply a subset of int
, and true continues to mean != 0
while false is always 0
. If you need to assing some value, some authors have inclined to use -1
as a value for true
(which is not normally the case, 1 and -1 are obviously different)