Anyone want to guess what gcc generates for a==b?0:a-b ? Any ideas why?
-
-
-
A similar case, also needed to deal safely with null pointers, gets optimized correctly: writing a<b as a!=b && a<b.
Show this thread -
Even more surprisingly, gcc fails to collapse the branch out of this: ptrdiff_t diff(char *a, char *b) { return a!=b ? a-b : (intptr_t)a-(intptr_t)b; } clang gets it right, though.
Show this thread -
Oh, fun. gcc <= 7 gets it right too. Only gcc 8 fails to collapse it. I wonder if this is new logic to prevent wrongly applying "pointer provenance" stuff to pointers cast to integers.
Show this thread
End of conversation
New conversation -
-
-
why is null special? If it's doing stupid pointer shenanigans, typecast both to long.
-
See this tweet and the followup.https://twitter.com/RichFelker/status/1040825909593485312 …
-
Fix the spec. Write code that works on everything you can find today (except windows), compiler then breaks it compiler is broken.
End of conversation
New conversation -
-
-
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.