Author: Jan Nijtmans <[email protected]> State: Final Type: Project Vote: Done Created: 02-Oct-2022 Tcl-Version: 8.7 Tcl-Branch: tip-641 Vote-Summary: Accepted 3/0/0 Votes-For: JN, KBK SL Votes-Against: none Votes-Present: none
This TIP proposes new behavior for public routines Tcl_GetBoolean
and Tcl_GetBooleanFromObj: It's
boolPtr argument can now point
bool as well as an
Since C99 (and also recent C++ compilers), there's a new
which can only have the values
false. Tcl predates this,
therefore it doesn't have an API to handle this type directly: In
bool the only portable way to use it, is use an
temporary variable, and convert it manually to the desired type.
For example, see here
(which uses the Microsoft-specific
BOOL, but the idea is the same).
Some platforms use
sizeof(bool) == sizeof(char), other platforms use
sizeof(bool) == sizeof(int). Therefore, we can implement this with
already existing functions (the
char variant depends on TIP #618).
We just define 2 macro's
map to the original functions if
sizeof(*(boolPtr)) == sizeof(int)
sizeof(*(boolPtr)) == sizeof(char).
A panic will result it none of those two match (but that's actually impossible
This implementation used to be part of TIP #618, but doing that led to a
lot of discussion. Since that TIP did multiple unrelated proposals,
it was decided to split it: TIP #618 introduces the new API which
makes this TIP possible at all. This TIP explains how the new API
can be used to handle the C99/C++
bool type, just be defining
two new macro's.
This is 100% upwards compatible.
Under development on the tip-641 branch.
This document has been placed in the public domain.