[tz] [PROPOSED 1/7] Avoid undefined behavior if no Link lines

Paul Eggert eggert at cs.ucla.edu
Thu Oct 27 16:41:05 UTC 2022


On 2022-10-26 23:38, Clive D.W. Feather wrote:

> You're assuming that NULL is represented by 32 or 64 zero bits [1].

No, I'm not assuming that. I'm aware of the AS/400 and its successor IBM 
i, whose C compiler ILE C does not use an all-bits-zero representation 
for null pointers. But as I understand it, on this legacy platform a 
pointer is internally represented by a memory space reference plus an 
offset, and adding 0 to a null pointer (using the ADDSPP instruction[1]) 
does not modify the offset and still gives you a null pointer. So I am 
unaware of any platform where (char *)0 + 0 does not give you a null 
pointer.

If I'm right, the C standard's prohibition of (char *)0 + 0 is 
unnecessarily restrictive, as it prohibits programs that are portable in 
practice.

It wouldn't be the first time that a standard is unnecessarily 
restrictive. Luckily, when writing free software we're free to ignore 
standards when they're wrong....

[1] 
https://www.ibm.com/docs/en/i/7.5?topic=instructions-add-space-pointer-addspp



More information about the tz mailing list