Ben Bacarisse <> writes:
> Keith Thompson <kst-> writes:
> <snip>
>> I just noticed something odd. C99 6.4.2.3p6 says:
>
> Does C99 have different numbering from n1256.pdf or is that a typo?
Typo; the numbering is the same (and I was using n1256 anyway).
>> Any pointer type may be converted to an integer type. Except as
>> previously specified, the result is implementation-defined. If
>> the result cannot be represented in the integer type, the
>> behavior is undefined. The result need not be in the range of
>> values of any integer type.
>>
>> I see no "previously specified" behavior for pointer-to-integer
>> conversions. (Conversion of a constant 0 to a pointer yields a null
>> pointer, but nothing is guaranteed for the reverse conversion;
>> (int)(void*)0) needn't yield 0.)
>
> I was puzzled by that, too. My guess was that maybe there had been,
> once, a requirement that a null pointer would convert back to (int)
> zero.
Jun Woong posted the answer in comp.std.c:
6.3.1.2 Boolean type [which precedes 6.3.2.3]
When any scalar value is converted to _Bool, the result is 0 if
the value compares equal to 0; otherwise, the result is 1.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"