Re:What is your favorite C programming trick? (2009)
by annilt on Sunday November 22, 2020 @12:17PM
(#25179096)
It’s added to the standard because macro version has undefined behavior. (yet it still works on any compiler without a problem)
Re:What is your favorite C programming trick? (2009)
by londons_explore on Sunday November 22, 2020 @03:05PM
(#25180577)
I was about to ask if it was legal to dereference a null pointer and then take the address of it... I presume it is not, but I'm surprised compilers don't complain at compilation time.
Re:What is your favorite C programming trick? (2009)
by saagarjha on Monday November 23, 2020 @03:52AM
(#25184819)
Dereferencing a null pointer and then immediately "undoing" it by taking its address is actually legal, I believe. I think the undefined behavior here is the member access instead of the magic sequence &* which is supposed to cancel out.
Still interesting to see the trick behind it tho.