Imagine you're debugging this code and now have to read through 3 files to understand this clang hack in order to learn if it is even relevant to your platform. Plus you can not even be sure if LTO will catch it when it comes to performance. With the #ifndef it would just deal with it in place, where a reader would care about it and you'd immediately see if the code lands in your build or not.
This is not clean code at all, this is tech debt it should not be admired as "elegant".
I hope Claude never writes such beautiful code.
PS: Great article as always, Abhinav. Got to learn something new.
Such a fun read! Love a good macro tricks like these
This is C gore.
The #ifndef solution is the only correct one.
Imagine you're debugging this code and now have to read through 3 files to understand this clang hack in order to learn if it is even relevant to your platform. Plus you can not even be sure if LTO will catch it when it comes to performance. With the #ifndef it would just deal with it in place, where a reader would care about it and you'd immediately see if the code lands in your build or not.
This is not clean code at all, this is tech debt it should not be admired as "elegant".