Previous:The #if...#else...#end Directives Main Index Next:The #switch, #case, #range and #break Directives

#### The #ifdef and #ifndef Directives

The `#ifdef` and `#ifndef` directive are similar to the `#if` directive however they is used to determine if an identifier has been previously declared.

IFDEF_DIRECTIVE:
`
  #ifdef (
` IDENTIFIER `)` TOKENS... [`#else` TOKENS...] `#end`
IFNDEF_DIRECTIVE:
`
  #ifndef (
` IDENTIFIER `)` TOKENS... [`#else` TOKENS...] `#end`

If the IDENTIFIER exists then the first group of tokens is parsed normally and the second set is skipped. If false, the first set is skipped and the second set is parsed. This is especially useful for replacing an undefined item with a default. For example:

#ifdef (User_Thing)

      // This section is parsed if the

      // identifier "User_Thing" was

      // previously declared

      object{User_Thing} // invoke identifier

     #else

      // This section is parsed if the

      // identifier "User_Thing" was not

      // previously declared

      box{<0,0,0>,<1,1,1>} // use a default

     #end

      // End of conditional part

The `#ifndef` directive works the opposite. The first group is parsed if the identifier is not defined. As with the `#if` directive, the `#else` clause is optional and the `#end` directive is required.

Previous:The #if...#else...#end Directives Main Index Next:The #switch, #case, #range and #break Directives