#ifdef usage in Rotor
I ran my #ifdef counter on the Rotor sources. The #ifdefs fall into a few categories:
- cross-platform, cross-Operating System, cross-compiler: . Eg, _x86_, _ppc_; PLATFORM_UNIX, Win32, _Win64, BIGENDIAN.
- preprocesser alternatives to #pragma once. Each of these would only occur once, at the top of a header file. These are the cases of :
#ifndef MyFile_h
#define MyFile_h
... contents of header ...
#endif - Extra debug-only checks. (_DEBUG, LOGGING)
- Toggling Features.
By far, most #defines were only used once (often as #pragma once alternatives).
number of #defines | ...that occured |
2 | 1000+ times |
6 | 100 to 1000 times |
76 | 10 to 100 times |
192 | 2 to 9 times |
1242 | 1 time (mainly for #pragma once) |
I wonder how many other software projects have similar distributions. I think it's interesting to consider how these could be reduced.
#1 (cross-platform/OS, compiler) could certainly be reduced by programming at a higher abstraction level. Using C/C++ as a shortcut for assembly language tends to produce a lot of #ifdef usage like this.
#2 (#pragma once) is purely a consequence of the C preprocessor's design choices. Other languages (like C#) don't even have this.
#4 (Features) is ideally solved by better componentization and better design abstractions.
Here were the top usages:
2249 _DEBUG
1266 DACCESS_COMPILE
389 _X86_
302 _MSC_VER
220 DECLARE_HELPERS
133 DEBUGGING_SUPPORTED
125 PROFILING_SUPPORTED
118 PLATFORM_UNIX
98 LOGGING
89 _PPC_
78 _DEBUG_IMPL
75 CHECK_APP_DOMAIN_LEAKS
74 __cplusplus
71 BIGENDIAN
59 _WIN64