Applications and Geodes: 5.1 The Error-Checking Version: Adding EC Code to Your Program

Up: GEOS SDK TechDocs | Up | Prev: 5 The Error-Checking Version | Next: 5.2 Special EC Routines

When compiling your code, you can include certain extra lines in either the EC version or the non-EC version of your program. For example, during debugging you want your program to check the validity of each memory handle before locking the memory block; for the final version of your program, however, you don't want this validity check because it slows down your program. You can easily add a few instructions that will be compiled only into the EC version.

GEOS provides five macros, listed below, for version-specific instructions. These macros must be treated as statements; they may not be used in expressions.

EC
This macro adds the specified line of code to the EC version only. When the non-EC version is compiled from the same code, the line will be left out.
EC_ERROR
This macro halts the execution of the EC version of a program by calling FatalError() with a specified error code. The call to FatalError() will not be included in the non-EC version.
EC_ERROR_IF
This macro works like EC_ERROR, above, but it also allows you to set a condition for whether FatalError() will be called. If the condition is met, FatalError() will be called.
NEC
This macro adds the specified line of code to the non-EC version but leaves it out of the EC version. (It is the converse of the EC macro.)
EC_BOUNDS
This macro checks the validity of a specified address (pointer) by calling the ECCheckBounds() routine. If the pointer is out of bounds, ECCheckBounds() will call FatalError() . This macro may only add the bounds check to the EC version.

An example of use of these macros is shown in EC Macros .

Code Display 7-4 EC Macros

/* This code display shows only the usage of these macros; assume that each
 * line shown below exists within a particular function or method. */
/* The EC macro adds a line of code to the EC version. Its format is
 *	EC(line)		where line is the line of code to be added.
 * Note that the NEC macro is similar. */
    EC( @call MyErrorDialogBox::MSG_MY_ERR_PRINT_ERROR(); )
    NEC( @call MyErrorDialogBox::MSG_MY_ERR_PRINT_NO_ERROR(); )
/* The EC_ERROR macro adds a call to FatalError() to the EC version. Its format is
 *	EC_ERROR(code)		where code is the error code to be called. */
    EC_ERROR(ERROR_ATTR_NOT_FOUND)
/* The EC_ERROR_If macro is similar to EC_ERROR but is conditional. Its format is
 *	EC_ERROR_IF(test, code)			where test is a Boolean value and code is the
 * error code to be called. */
    lockVariable = MyAppCheckIfLocked();					/* TRUE if inaccessible. */
    EC_ERROR_IF(lockVariable, ERROR_ACCESS_DENIED)						/* Error if inaccessible. */
/* The EC_BOUNDS macro adds a call to ECCheckBounds() to the EC version.
 * Its format is
 *	EC_BOUNDS(addr)		where addr is the address to be checked. */
    myPointer = MyAppGetMyPointer();
    EC_BOUNDS(myPointer)

Up: GEOS SDK TechDocs | Up | Prev: 5 The Error-Checking Version | Next: 5.2 Special EC Routines