Some subsurface notes from a week of diving

Linus Torvalds torvalds at linux-foundation.org
Mon Mar 17 11:12:31 PDT 2014


On Mar 17, 2014 10:57 AM, "Thiago Macieira" <thiago at macieira.org> wrote:
>
> Actually, the compiler is allowed in this case to assume that dive is
never
> null.

I think you are confused. Or the standard has been corrupted by crazy C++
people. Because  arithmetic on NULL pointers is both traditional and
common, exactly because of sequences like the one under discussion (in
addition to offsetof. Which is hidden in header files).

The compiler is allowed to assume that the *result* of the arithmetic is
not NULL, because pointer arithmetic is only well-defined if it stays
within an object, and that explains the offsetof thing you point to (since
that very much uses the result). Even then, a compiler that actually
miscompiles the traditional format is just crap.

But that says absolutely nothing about the base pointer.

Where in the standard does it say that you can't do arithmetic before
testing a NULL pointer, and who can I shoot at for messing things up
*again* if it actually does say that?

Because I think you are wrong. The standards people have done many stupid
things, but this would be beyond stupid.

     Linus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20140317/c81587da/attachment.html>


More information about the subsurface mailing list