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

Brian Inglis Brian.Inglis at SystematicSw.ab.ca
Thu Oct 27 22:53:10 UTC 2022


On 2022-10-27 10:41, Paul Eggert via tz wrote:
> 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

Itanium NULL pointer representation is -1:

	https://refspecs.linuxfoundation.org/cxxabi-1.75.html

See 2.3 Member pointers, which also states pointer value zero is NULL.

-- 
Take care. Thanks, Brian Inglis			Calgary, Alberta, Canada

La perfection est atteinte			Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter	not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer	but when there is no more to cut
			-- Antoine de Saint-Exupéry


More information about the tz mailing list