5 ms·
Where? The post cites C11 section 6.5.8 paragraph 5, which seems to disagree with you. Of course == comparing unrelated pointers is something you need to be ab
by Rusky 8y ago
Where? The post cites C11 section 6.5.8 paragraph 5, which seems to disagree with you.
Of course == comparing unrelated pointers is something you need to be able to do, but relational comparisons (including those based on pointer arithmetic) don't seem to be defined anywhere...
- jjnoakes 8y agoRight, comparisons with < and > are UB, but I'm talking about ==, which is well-defined. It's hard to tell which operator "tzahola" was originally talking about, but I took "comparing the address" in this context (especially given his example code) to mean "==", or at least, include it, which makes the statement "comparing the addresses of stack variables is undefined behavior" incorrect in this context.
- tzahola 8y agoYou're right. There's no undefined behaviour for ==: Two pointers compare equal if and only if both are null pointers, both are pointers to the same object (including a pointer to an object and a subobject at its beginning) or function, both are pointers to one past the last element of the same array object, or one is a pointer to one past the end of one array object and the other is a pointer to the start of a different array object that happens to immediately follow the first array object in the address space.