Scope of Preprocessor Directives

The conditional constructs #if, #ifdef, and #ifndef must be contained entirely within a single file.

The scope of the #define directive is limited to a header file in which this directive resides, plus all files that include this file with the (#) include, #includeb, or (#)includepp directives.

A #define directive placed in a source file is only visible in this source file.


Scope of #define Directives Placed in Source and Header Files

Like variable defines or declarations, preprocessor identifiers created with the #define directive are visible from the line where they are defined onwards.

Unlike variables, the scope of a preprocessor identifier always extends to the bottom of a file (or to the bottom of all files that include this file).

There are no local scopes and sub-scopes for preprocessor definitions. Here is a code example:

Tibbo BASIC
sub on_sys_init
   dim f as byte
   for f=0 to 10
      dim s as string      'this variable's scope is limited to the for-next loop it resides in
      #define NUM_ITEMS 10 'this macro is visible from here to the end of the file
   next f
end sub

Scope of Preprocessor Identifiers Defined in the Customize Project Dialog

Global preprocessor identifiers (from the Customize Project dialog) are visible everywhere in your project.


Scope of Preprocessor Directives

Scope of #define Directives Placed in Source and Header Files

Scope of Preprocessor Identifiers Defined in the Customize Project Dialog