Bug 1: the compiler allowed an invalid typecast.
But how else to do it, the smallest type size being byte/char (8 bits)?
Pascal does not provide a native one-bit type (which should be used for booleans).
True, the smallest _addressable_ size is byte. In the case of boolean, the type size and the storage size can differ (they don't in the case of a bitpacked array of boolean). When dealing with booleans the compiler should use the type size _not_ the storage size. The storage size affects addressability but never affects the fact that a boolean is a single bit. The compiler should make that distinction.
All that said, since Delphi accepts the invalid typecast, it is rather unlikely that this bug will be corrected (because Delphi compatibility is more "important" than correctness.)
It's also interesting that the majority of posters, including myself, consider the cast to be invalid but, there is no mention that the compiler should not allow the invalid cast. IOW, the compiler accepts something it should not accept but, if and when a programmer uses that invalid construction, it's not the compiler's fault, it's the programmer's. ain't that great ? Talk about the guilty party pointing the finger at someone else and saying "he did it !"
@Martin,
You're right that math does not say how a boolean should be stored BUT, it does say that it has only two states and, in a computer that's a bit. No way around it. boolean = 2 states = 1 bit.
It doesn't matter how it is stored, the number of states is the same: 2 and only 2. Therefore, by definition, a boolean occupies a single bit.
Due to addressability reasons, that single bit is usually part of a byte or word or dword or qword but, no matter the container, it is and will always be a single bit.
The bottom line is simple: no matter how many bits there are in the container,
only 1 bit is significant, the rest are not and they are not part of the type therefore the compiler should NOT allow their being manipulated because they are not used to represent the type's value.
It is incorrect and meaningless for the compiler to allow the non-significant bits to be manipulated and, if for convenience or compatibility with Delphi, it decides to allow it then those bits should always be ignored because they are not part of the data type, just "tolerated" guests in the container to enable simple addressability.