{ } Preprocessor name reference
References the value of a preprocessor name in any ABL or preprocessor expression.
Syntax
Enter the braces ({}) as shown; they do not represent syntax notation in this description.
&preprocessor-name
Expands the name,preprocessor-name
, to its defined value. You can define preprocessor names using either the &GLOBAL-DEFINE preprocessor directive or the &SCOPED-DEFINE preprocessor directive. ABL also provides a set of built-in preprocessor names that you can reference for a variety of session information. Table 3 lists each built-in preprocessor name with its description.
Table 3: Built-in preprocessor names The preprocessor name . . . Expands to an unquoted string . . . BATCH-MODE Equal to "yes" if the Batch (-b
) startup parameter was used to start the client session. Otherwise, it expands to "no". FILE-NAME That contains the name of the file being compiled.1 If you want only the name of the file as specified in the { } Include File Reference, the RUN statement, or the COMPILE statement, use the argument reference {0}. LINE-NUMBER That contains the current line number in the file being compiled. If you place this reference in an include file, the line number is calculated from the beginning of the include file. OPSYS That contains the name of the operating system on which the file is being compiled. The OPSYS name can have the same values as the OPSYS function. The possible values are “UNIX” and “WIN32".2 SEQUENCE Representing a unique integer value that is sequentially generated each time the SEQUENCE preprocessor name is referenced. When a compilation begins, the value of {&SEQUENCE} is 0; each time {&SEQUENCE} is referenced, the value increases by 1. To store the value of a reference to SEQUENCE, you must define another preprocessor name as {&SEQUENCE} at the point in your code you want the value retained. WINDOW-SYSTEM That contains the name of the windowing system in which the file is being compiled. The possible values include "MS-WINDOWS", "MS-WIN95", "MS-WINXP", and "TTY".3
1When running the source code of a procedure file loaded into the Procedure Editor or the AppBuilder, {&FILE-NAME} expands to a temporary filename, not the name of the file under which the source code might be saved.
2ABL supports an override option that enables applications that need to return the value of MS-DOS for all Microsoft® operating systems to do so. For example, if you do not want the value WIN32 to be returned when either Windows 95 or Windows NT operating systems are recognized, you can override this return value by defining the Opsys key in the Startup section of the current environment, which can be in the registry or in an initialization file. If the Opsys key is located, the OPSYS function returns the value associated with the Opsys key on all platforms.
3ABL supports an override option for the &WINDOW-SYSTEM preprocessor name that provides backward compatibility. This option enables applications that need the WINDOW-SYSTEM preprocessor name to return the value of MS-WINDOWS for all Microsoft operating systems to do so. To establish this override value, define theWindowSystem
key in the Startup section of the current environment, which can be in the registry or in an initialization file. If theWindowSystem
key is located, the WINDOW-SYSTEM preprocessor name returns the value associated with theWindowSystem
key on all platforms.Table 4 lists the additional built-in preprocessor names that apply to SpeedScript.
ExamplesThe
r-prprc1.p
procedure shows how you can reference a built-in preprocessor name and include it in a character string.
The procedure
r-prprc2.p
shows how to capture the value of a {&SEQUENCE} reference. In this example, {&SEQUENCE} is referenced three times, once each to assign its value towvar
(0) andxvar
(1) at run time. The third reference defines the preprocessor name Last-Value with the value 3. As shown, Last-Value is assigned unchanged to bothyvar
andzvar
, each of which take the value 3 at run time.
The procedure
r-prprc3.p
shows how preprocessor names override compile-time arguments. In this example,r-prprc3.p
defines the preprocessor name My-Name as "Daniel". It then passes the compile-time argument My-Name, with the value "David", to the include filer-prprc3.i
, which in turn defines a preprocessor name My-Name as "Donald".
During execution, the first message included by
r-prprc3.i
displays the value of the My-Name argument, "David". The second message included byr-prprc3.i
displays the value of the following My-Name preprocessor name, defined as "Donald", permanently overriding "David" passed by the My-Name argument. Finally, the message inr-prprc3.p
displays the value of the My-Name preprocessor name that was initially defined there, "Daniel", because the value from My-Name established inr-prprc3.i
("Donald") went out of scope during compilation.Note also that the reference to the My-Name compile-time argument in
r-prprc3.i
is inside double-quotes, because ABL passes string constant values for compile-time arguments without the surrounding double-quotes.You can encounter compilation problems mixing preprocessor names with compile-time argument names. The following example, a variation of
r-prprc3.i
, does not compile, even when passed a My-Name argument as an include file. This is because the preprocessor My-Name value overrides the argument My-Name value, as shown:
Because the preprocessor My-Name defines a quoted "Donald" value, ABL replaces "{&My-Name}" in the fourth line with ""Donald"". This appears to the compiler as two empty strings and an unknown variable reference (Donald). Although you can do it with care, in general, avoid using the same names for compile-time arguments and preprocessor names.
Notes
- ABL expands preprocessor names wherever and in whatever context it finds them, including inside quoted character strings.
- If you define a preprocessor name in the same file and with the same name as a compile-time argument passed to the file, the value of the preprocessor name takes precedence over the value of the argument name from the point where the preprocessor name is defined.
See also&GLOBAL-DEFINE preprocessor directive, &SCOPED-DEFINE preprocessor directive, { } Argument reference, { } Include file reference, ; Special character
OpenEdge Release 10.2B
|