Some subsurface notes from a week of diving
Thiago Macieira
thiago at macieira.org
Mon Mar 17 12:26:17 PDT 2014
Em seg 17 mar 2014, às 12:07:59, Linus Torvalds escreveu:
> On Mon, Mar 17, 2014 at 11:12 AM, Linus Torvalds
>
> <torvalds at linux-foundation.org> wrote:
> > 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?
>
> I don't have access to the real standard, but I do have access to the
> draft standard that is public, and can find no sign of language saying
> that taking the address of a member generates undefined behavior.
I can't find anything either, in either C11 or C++1y drafts.
I was going about this change in Qt:
https://qt.gitorious.org/qt/qtbase/commit/88cf9402e336fddeb673c92f3c14da47a9f8450b
In it, we had to change a d->getAndRef() call to Data::getAndRef() because d
was used when it was still null. However, the part of the C++ specification
that says this is bad does not exist in C. It's there to guarantee that if you
write:
function()->staticmember;
Then function() is still called, even though the access to staticmember did
not require so.
That means
&dive->staticmember;
would be undefined behaviour.
If "member" were inherited from a virtual base, then
&dive->member;
would also be undefined because it needs to dereference dive to get to the
virtual sub-object.
Neither of those cases apply to C code and POD structures in C++.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
More information about the subsurface
mailing list