------- Additional Comments From falk at debian dot org  2005-07-15 06:41 
-------
Subject: Re:  pointer +- integer is never NULL

"gdr at integrable-solutions dot net" <[EMAIL PROTECTED]> writes:

> My indirect observation was that reinterpret_cast is intended for
> specific needs that cannot adequately be expressed at the purely
> object type level.  The result is intended to be unsurprising to
> those who know the addressing structure.  Consequently it takes a
> creative compiler to make reinterpret_cast<int*>(0) + 5 undefined.

Sorry, I cannot follow you. I'd find it massively unsurprising if
reinterpret_cast<int*>(0) produces a null pointer, and if I then get
undefined behavior for doing something with it that is undefined for a
null pointer. In fact I'd find it very *surprising* if
reinterpret_cast<int*>(0) behaves different than a normally
constructed null pointer anywhere.

> Furthermore, given the mapping chosen by GCC, it takes even more
> creative compiler to make (int *)0 + 5 also undefined.

And I don't see how that follows, either.

As it seems, arguing with different levels of surprisingness seems to
be somewhat subjective, so I don't think this leads us anywhere.

> There still are reasonable codes for system programming out there
> that needs the to go through the play with null pointer -- we, GCC,
> even used to distribute such things in the past.

This is a more relevant point. I don't think this optimization would
break offsetof-like macros, since they'd use null pointer *constants*,
which we could easily avoid to tag as non-null.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22485

Reply via email to