answersLogoWhite

0

#define is a pre-compiler directive which is used to define a macro. All occurrences of the defined macro within your source code are replaced by the macro definition prior to compilation. In other words, your code is altered to produce an intermediate file which is actually compiled, just as if you'd copy/pasted the macro definition throughout your code. However, the end result is that the compiler cannot identify any problems within your macros since they will no longer exist in the intermediate file. Macros are not type safe, thus they are generally frowned upon, especially when they are used to define complex functions. However, correct usage of macros can greatly simplify your code and ultimately permit the compiler to build different versions of your code, depending upon which definitions you define. For instance, you will typically use slightly different versions of some functions depending on whether you are building a debug or release version of your code, and will typically #define DEBUG for debug builds. You can also cater for cross-platform coding by filtering platform-specific functions using macro definitions. You alter the type of the build simply by defining the appropriate definitions, either within the code itself (using #define), or via the compiler's pre-processing command line switches, or a makefile script.

User Avatar

Wiki User

11y ago

What else can I help you with?