Progress
Programming
Handbook


Preprocessor Name Scoping

Each preprocessor name that you define has a specific scope. The scope of a name is the area within its compilation unit where you can access, or reference, the name. You determine the scope of a preprocessor name by where you define it within the compilation unit and by whether you define it with the &GLOBAL-DEFINE or &SCOPED-DEFINE directive. A name defined with the &GLOBAL-DEFINE directive is globally defined; a name defined with the &SCOPED-DEFINE directive is nonglobally defined.

The scope of a preprocessor name always begins at the directive that defines it; the name is not accessible before the defining directive.

The scope of a globally defined name extends forward from the point of definition to the end of the compilation unit. The scope of a nonglobally defined name extends forward from the point of definition to the end of the file that contains its definition. It does not extend beyond the end of the file to the rest of the compilation unit. It does, however, extend to any files included within the defining file.

If you define a name in a top-level file of a compilation unit, it makes no difference whether the name is globally defined or nonglobally defined. In either case, the name is accessible from the point of definition to the end of the compilation unit. However, if you define a name within an include file, it does make a difference how the name is defined. Globally defined names are accessible to the end of the compilation unit; nonglobally defined names are only accessible within the defining file. See Figure 8–1.

main.p
include.i

Figure 8–1: Name Scoping

In Figure 8–1, the preprocessor name SOURCE-NAME is defined both globally and nonglobally. In such a situation, the nonglobally defined name takes precedence over the globally defined name within its scope. The nonglobally defined name’s scope begins at the first line and ends at the last line of the file include.i. Within this scope, all references to SOURCE-NAME access the defined value “include.i”.

The innermost name definition always takes precedence within its scope. If you define a name nonglobally and then redefine the name nonglobally within a nested include file, only the innermost name definition is accessible within the nested include file.

You can limit the scope of a name with the &UNDEFINE directive. This directive undefines the name and ends its scope.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095