| glen herrmannsfeldt 2008-01-22, 7:27 pm |
| James Van Buskirk wrote:
(snip)
> Oog. Looking at the C99 standard, I see that _Bool, although it's
> an integer type, has semantics distinct from int. In particular,
> when conversion to _Bool is required any mumeric value that isn't
> zero gets converted to 1 (didn't carefully check what happens to
> imaginary values, though) and the example given in the standard is
> that (int)0.5 = 0, but (_Bool)0.5 = 1 . That means that I have
> introduced a red herring into my own argument in that LOGICAL(C_BOOL)
> is to preexisting Fortran LOGICAL kinds what IEEE-754 data types are
> to, say, VAX floating types like G_FLOAT.
This makes some sense even regarding C89.
In C89 when a logical value is required, as for a logical operator
or if() statement, any non-zero value is considered true.
Floating point values are not converted to int first.
if(0.5) printf("0.5 is true");
I haven't looked at C99 much, but it would seem to make sense in
extending to complex values that non-zero imaginary values would
also be true.
-- glen
|