Some subsurface notes from a week of diving
Thiago Macieira
thiago at macieira.org
Mon Mar 17 12:28:46 PDT 2014
Em seg 17 mar 2014, às 11:12:31, Linus Torvalds escreveu:
> 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.
Indeed:
struct D { int i; int j; };
int f(struct D *d)
{
int *p = &d->j;
if (!p)
return -1;
return *p;
}
Clang 3.4 removes the check for !p. ICC 14.0 and GCC 4.9 don't.
--
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