3 ms·
#ifdef should be shot
by SixSigma 12y ago
#ifdef should be shot
- Sanddancer 12y agoThere are definitely times when it's overused, and times when it could be factored out. However, when you're dealing with the low level stuff a compiler that targets multiple architectures has to, using preprocessor defines can make things less maddening. GCC targets architectures that have all sorts of weird quirks regarding register locations and visibility, memory models, etc, that need to be accounted for. Without those #ifdefs, the code could very well be uglier with redundant checks, even uglier if statements, etc.
- frozenport 12y agoThere is no other mechanism to choose between <windows.h> and <linux.h>
- SixSigma 12y agoPlan 9 manages to build the whole OS and userland for multiple architectures without using ifdefs, even cross compiling across CPUs with different endianness