Comparing pointers in C and D

Olivier Pisano olivier.pisano at laposte.net
Wed Feb 15 20:07:35 UTC 2023


Hello,

Today a colleague of mine gave me a link to this article about 
comparing pointers in C :

https://pvs-studio.com/en/blog/posts/cpp/0576/


Playing with the first code example in Compiler explorer, it 
seems that the pointer comparison is always false in GCC once 
optimizations are enabled, while it is always true with Clang, no 
matter the optimization level.

What bothers me is that the same behavior can be observed 
respectively with GDC (false) and LDC (true), at least with the 
versions available in compiler explorer.

Does the D spec define pointer comparison semantics ? What should 
the correct behaviour be? I can understand the C standard wording 
in regards to segmented memory archs, but I must admit I have 
trouble justifying it on a PC with linear address space...

Best regards.


More information about the Digitalmars-d mailing list