Adriaan van Os wrote:
Frank Heckenbach wrote:
Adriaan van Os wrote:
So we have the choice either to leave the range at False {0} .. True {1}, and forbid other values, and change the test programs,
In my opinion, the only correct option.
Then I doubt whether we need such types at all (unless required for compatibility to Delphi or something).
or to really declare the range according to the bitsize (e.g. False {0} and 255 values of True for an 8 bit type).
The former would seem more Pascalish. OTOH, such types are probably often used for C interfaces, and what will happen if C routines put values > 1 in them?
Use an integer or cardinal type instead (for example in the Win32 API, but that API is a mess anyway, dependent on the call you have to check for <> 0 or = 0 or <> 1 or =1).
I don't know this API. Do you mean there are functions where 0 means False, 1 means True, but 2, 3, ... means False? (Or vice versa?) Ouch!
Some examples (but I have seem more weird cases)
SystemParametersInfo <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ sysinfo/base/systemparametersinfo.asp> If the function succeeds, the return value is a nonzero value. If the function fails, the return value is zero. To get extended error information, call GetLastError.
SHGetPathFromIDList <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ wceshellui5/html/wce50lrfshgetpathfromidlist.asp> TRUE indicates success. FALSE indicates failure.
DeviceCapabilities <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/ prntspol_21bn.asp> If the function succeeds, the return value depends on the setting of the fwCapability parameter. A return value of zero generally indicates that, while the function completed successfully, there was some type of failure, such as a capability that is not supported. For more details, see the descriptions for the fwCapability values. If the function fails, the return value is -1.
Hm, now that I have written this down, I start to wonder if "boolean attribute ..." wasn't invented to be compatible with the Win32 API. I had a look at the Borland Delphi 3 Object Pascal Language Guide (page 4-5 to 4-6).
"Boolean types There are four predefined Boolean types: Boolean, ByteBool, WordBool and LongBool. Boolean values are denoted by the predefined constant identifiers False and True. Because Booleans are enumerated types, these relationships hold:
Boolean ByteBool, WordBool, LongBool False < True False<>True Ord( False) = 0 Ord( False) = 0 Ord( True) = 1 Ord( True) = any non-zero value Succ( False) = True Succ( False) = True Pred( False) = True Pred( False) = True "
(I wonder if the last line isn't a printing error meant to say Pred( True) = False)
"Boolean and ByteBool variables occupy one byte, a WordBool variable occupies two bytes (one word) and a LongBool variable occupies four bytes (two words). Boolean is the preferred type and uses the least memory: ByteBool, WordBool and LongBool primarily exist to provide compatibility with other languages and the Windows environment.
A Boolean variable can assume the ordinal values 0 and 1 only, but variables of type ByteBool, WordBool and LongBool can assume other ordinal values. An expression of type ByteBool, WordBool or LongBool is considered False when its ordinal value is zero, and True when its ordinal value is nonzero. Whenever a ByteBool, WordBool or LongBool value is used in a context where a Boolean value is expected, the compiler will automatically generate code that converts any nonzero value to the value True."
So far the Borland Delphi 3 Object Pascal Language Guide.
Looks like, for compatibility, we have to distinguish clearly between the Pascal Boolean type and C-derived "integer" booleans, for example:
ByteBool = IntBoolOfBitSize (8) WordBool = IntBoolOfBitSize (16) LongBool = IntBoolOfBitSize (32)
again deprecating "boolean attribute ..."
Regards,
Adriaan van Os