|Titan Architecture Internals: On the difference between the bool and boolean types [message #1749598]
||Thu, 08 December 2016 13:50
| Kristof Szabados
Registered: July 2009
One of the big secrets of Titan development is difference between the types bool and boolean.|
The difference between them is ... that none of them actually exist .
/* this is more of an advanced C/C++ topic */
How does it come that in the runtime part of the titan.core (core/core folders and the generated codes) we use "boolean" everywhere to represent true/false values?
To understand this, we have to start with the fact that neither bool nor boolean did exist according to the C and C++ standards for a long time.
Till 1999 everyone wrote his/her bool type by re-defining an int, and defining some values for it.
For this reason, when the work on Titan started around 2000, every system (operating system, compiler version, tooling, etc..) had its own bool type.
On some systems it was a true/false vale ... on other systems it was TRUE/FALSE, on yet another system it could be true/false/maybe/unknown.
For this reason, when C99 introduced it into the C standard they choose to use the _Bool name.
Making it available in stdbool.h with the "bool", "true", "false" words as #define -s.
Which does not conflict with any previous implementation ...
but at the same time it was yet another name to be prepared for
and yet another complexity to see which source codes include stdbool.h on some way and which not.
Please also note, that by now it is supported by most vendors: Apple , GCC and CLANG.
But they have somewhat different #defines, and support did not appear at the same time in these tools.
(also users tend to take their time when refreshing their systems)
So what about C++?
Officially the bool type only got into the C++ standard in 2011.
Since then we can use the "bool", "true", "false" words as keywords in the language.
/* fun fact: If you are interested in the standard, the draft version of the latest C++ standard is available here (it is only 1586 pages to read )
Which brings the obvious benefit of having standard language elements.
But comes at a cost:
- name clashes with previous implementations
- "thanks to" implicit transformations, old 0/1 numbers transfer without a warning ... making it very easy for developers to neglect the consistent updating of their codes.
- is only available in C++ codes
- different vendors made it available in different points of time
- and is yet another name for this type.
To solve this complexity and have the wide range of platforms we can support, we had to have our own "boolean", which we at least have in our control.
This way it is not a problem if some platform does not yet support it, or if the platform supports some special bool type ... we can just simply modify our definition to reflect that type, in one place (compiler2/datatypes.h:30).
Keeping the consistency of the runtime system.
The only drawback here is, that "boolean" also only exist within Titan and as new members are not familiar with it ... we sometimes need to run some "refactoring to boolean" tasks to keep the consistency of the system.
Powered by FUDForum
. Page generated in 0.01844 seconds