Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 9. Writing Macros > Defining Macros

9.2. Defining Macros

You begin a macro definition with the # symbol followed by the preprocessor directive and then any parameters to the directive such as the name of the macro and so on. Table 9.1 shows a listing of the most commonly used preprocessor directives.

Table 9.1. Table 9.1
DirectivePurpose
#defineUsed to define new macros such as constants and functions.
#ifdefBegins an optional compilation block. If the parameter for the preprocessor directive is defined to be anything (even zero), then the code following the #ifdef up until a terminating #endif, #else, or #elif will be compiled and included in the application. If the parameter is not defined and an #else or #elsif block is provided, then the #else or #elsif block will be evaluated and if appropriate compiled and included in the application.
#undefRemoves a previously defined macro.
#importReads and includes another source file in this file. Guards against including the file multiple times automatically.
#includeReads and includes another source file in this file. Does not prevent including a file multiple times.
#pragmaSpecial macro used for configuring the compiler and for annotations in the IDE.
#warningGenerates a compiler warning. Used to flag issues to the developer.
#errorGenerates a compiler error.
#ifBegins a conditional compilation block similar to #ifdef, but relies on an expression (such as X > 10) which must evaluate to true in order to be considered true.
#elseUsed after an #if or #ifdef to provide a conditional block to be compiled if the statement is false.
#elifUsed after an #if or #ifdef to provide an additional conditional block with an additional control statement to determine if it should be compiled.
#endifTerminates an #if, #ifdef, #else, or #elif block.



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial