Clark S. Cox III said:
Yes, it is UB. As an example:
Consider a platform that has separate data and address registers. Also
consider that this platform has virtual memory, and that free() unmaps
the passed-in pointer from the address space. The mere act of loading
the p1 pointer into a register in order to compare it to another
platform could cause a bus error, crash the program, etc.
Isn't it UB even if p1 isn't freed, because p1 and p2 do not point
within the same object?
Consider the old segmented architecture of the 8088 CPU, and assume
that you are compiling in a mode that uses "far" pointers. If the
mallocs happen to return:
p1 = 0x1000:0xff00 (absolute address 0x1ff00)
and
p2 = 0x2000:0x0010 (absolute address 0x20010)
The code generated by the compiler can (correctly, as far as the
Standard is concerned) claim that "p1 > p2" is true, because the
offset 0xff00 is greater than the offset 0x0010.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |
www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net |
www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:
[email protected]>