Popular Posts

Sep 25, 2011

Available Preprocessor Directives


#define: Used to define the compilation identifier, such as the INTEGRATE_
TESTS identifier used in this chapter’s example. You would define this
at the top of a source code file to activate conditional preprocessor
statements used throughout the source code file. Using a #define
directive does not span multiple source code files.

#undef: Used to undefine an identifier. You would use #undef if you wanted
to change a global setting. Let’s say that an identifier is set globally,
but for a particular source code file, you want the behavior as if the
identifier were not set. In that case, you use #undef. Another way to
achieve this behavior is to use the ! character in front of the identifier.

#if and #endif: Used to conditionally include or not include a piece of source code.You would use a conditional directive whenever you wanted to define
source code configurations, such as for debug or production builds.

#elif: Instead of a single #if block, you could have multiple tests for code
inclusion. You would use #elif when you have more than a single
preprocessor directive, such as for debug, production, and performance
builds.

#else: A default code block that is included if the other #if statements did
not trigger.

#region and #endregion: These have absolutely nothing to do with the compilation of the source code. They are used by Visual Studio to create regions of source code that can be “folded.” Folding means to collapse a block of code
out of sight temporarily. Source code files can become long, and constantly
paging up and down becomes tedious. By folding the code,
you are reducing the amount of times that you need to page up and
down, even though the code still exists.

No comments:

Post a Comment