3 ms·
The post hinges on the faulty assumption that calculating the address of an lvalue "evaluates" that lvalue. This is not so. Any compiler that generates anythin
by jwatte 12y ago
The post hinges on the faulty assumption that calculating the address of an lvalue "evaluates" that lvalue. This is not so.
Any compiler that generates anything other than an add instruction (or lea or similar) is broken, for rather unsubtle reasons.
Or to put it another way: dereferencing a null pointer may be undefined, but arithmetic on any pointer (including null) is well defined, and the code in question is arithmetic, not dereference.
And, yet another broken blog post will make the rounds on the internet every three years and confuse even more people. It's sad.
- pcwalton 12y agoThe post cites the spec. The C standard clearly seems to state that & must reference "an object", and NULL does not reference an object. A "pointer to any object" is distinguished from a null pointer. Do you have links stating otherwise?
- Gibbon1 12y agoAn of course plain C does not have 'objects' and a _lot_ of architectures have stuff mapped at address 0x0
- aidenn0 12y agoC absolutely does have objects.
- rcfox 12y agoWhile C is not an "object-oriented" language, it does have a concept of an object: http://port70.net/~nsz/c/c99/n1256.html#3.14p1 http://port70.net/~nsz/c/c99/n1256.html#3.14p1
- nullc 12y agoYou may be mistaking C for a fancy macro assembler. It's not-- It's a high level language, even though a fairly low level looking one. The obligation of the language is to behave as the spec says, and there may not be a close mapping between your program and what runs on the machine, though there often is. An "Object" is a concept defined and used extensively in the language specification; "a region of data storage in the execution environment,".