[fpc-devel] compiler bug?

DrDiettrich drdiettrich at compuserve.de
Sat Jan 1 06:29:25 CET 2005

Nico Aragón wrote:
> > > IIRC, any non-zero value is evaluated as "True" for a Boolean variable.
> >
> > You should not guess about any implementation.
> I don't. Do I?

Yes, you do. How can you know what bit pattern is stored in a boolean
variable? Using typecasts may result in silent type conversion,
returning something different from the really stored pattern.

The boolean data type is distinct from other data types, so that it's
wild guessing that every compiler and compiler version will treat
boolean values and variables in the same way, as observed when using a
specific version of an specific compiler.

For completeness: Many people also consider ByteBool etc. as being
"boolean". These types have been made compatible with boolean
*intentionally*, with the documented behaviour that any non-zero value
will evaluate to True, under circumstances. But you may test yourself
what will happen when you compare such a variable with an non-boolean
value - it's not perfectly specified when the nonzero=true evaluation
will be effective. Try this with various compilers:

var b: ByteBool;
case b of
True: ...
False: ...
42: ...
else ...

It's unspecified which compiler will accept the True and False constants
here at all...


More information about the fpc-devel mailing list