Conditional Compilation in R/BASIC (TB#109) (Functions/Subroutines/Programs)

Conditional Compilation in R/BASIC

In Advanced Revelation 2.12 the R/BASIC compiler, RTP5, supports conditional compilation. This bulletin describes how you use conditional compilation in your programs.

Note: Careful use of conditional compilation can make it easy to use the same program in a variety of slightly different situations. Overuse of the feature can lead to programs that are difficult to read and maintain.

When your program is compiled, the source code is first passed through two preprocessors. The first, the IFDEF preprocessor, is the one described here. The second strips out comments and extra whitespace.

The IFDEF preprocessor looks for special words in your code and, depending on the action indicated, turns additional lines into comments. The comments can then been stripped by the second preprocessor.

Supported Commands

IFDEF supports five directives. Each directive must appear on a line by itself and must be preceded by a #.

The value of label can be any alphanumeric string.Spaces are not allowed.

DEFINE label

DEFINE designates a label that subsequent IFDEF and IFNDEF commands look for. IFDEF and IFNDEF branch based on whether or not a label is defined. You can define more than one label.

#DEFINE VERSION212

#DEFINE DEVELOPER

UNDEFINE label UNDEFINE is used to stop tracking a label. You use this to turn off checking.

#UNDEFINE VERSION212

IFDEF label

Use IFDEF to indicate that the following lines should be compiled only if the label is defined. If the label is not defined, the lines are not compiled.

#IFDEF VERSION212

MSG(This is version 2.12)

#ENDIF

IFNDEF label Use IFNDEF to indicate that the following lines should be compiled only if the label is not defined.

#IFNDEF VERSION212

MSG("This isn't version 2.12",,,) #ENDIF ENDIF ENDIF identifies the end of the block of code to compile conditionally. Figures 1 and 2 show how the directives can be used in programs. The COMPILE Command The DEFINE directive is currently supported only in the source code. A future release of Advanced Revelation will allow you to set your DEFINEs from the command line by using the COMPILE command. Figure 1 /* Define a switch to be used when debugging the program */ /* Comment out the following line when debugging is complete */ #DEFINE DEBUG CNTR = 1 LOOP CNTR += 1 UNTIL CNTR > 100 /* Processing here */ #IFDEF DEBUG MSG('CNTR = %1%',,,CNTR) DEBUG #ENDIF REPEAT Figure 2 /* This program shows how the IFDEF processor might be used to support customers in the field using multiple versions of Advanced Revelation. It assumes that the program is being *compiled* under version 2.12 */ DECLARE SUBROUTINE MSG,FSMSG #DEFINE 212 ;* Comment out this line when compiling for non-2.12 customers EQU TRUE$ TO 1 EQU FALSE$ TO 0 TABLENAME = 'SAMPLE_CUSTOMERS' OPEN TABLENAME TO REPORT_TABLE ELSE FSMSG() STOP END SELECT REPORT_TABLE DONE = FALSE$ LOOP READNEXT KEY ELSE DONE = TRUE$ END UNTIL DONE READ RECORD FROM REPORT_TABLE, KEY THEN COMPANY = RECORD<1> #IFDEF 212 MAP = 'T1' MAP<5> = '@@EW' ;* Blinking border MSG(COMPANY, MAP,,) #ENDIF #IFNDEF 212 MSG(COMPANY,T1,,'')

#ENDIF

END

REPEAT

  • kb/kb_articles/kb0053.txt
  • Last modified: 2024/01/30 13:36
  • by 127.0.0.1