NESHLA: Reference: Preprocessor Keywords:
 Defines

NESHLA includes preprocessor keywords for defining labels which can store code and data, or control compilation flow.

 Definition Declarations

 #define label[, value]

The #define directive gives the ability to eliminate code duplication and enhance code readability. By defining magic numbers with names, code readability can be enhanced, and adjustments can be made easily.

Defines can be used with the conditional preprocessor define directives as well to control the compiler's compilation. See Conditional Defines.

Examples

// defining boolean true/false integers
#define TRUE  1
#define FALSE 0

// defining an integer for the size of a name table
#define NAME_TABLE_SIZE 0x03C0

// defining a string
#define PROGRAM_VERSION "Version 1.0"

// defining a binary bitmask
#define ST_VBLANK %10000000

// defining a condition control
#define DEBUG_BUILD


 #undef label

The #undef directive allows the deletion of previously defined labels. It is useful when limiting a define to a certain scope. As well, it can be useful for use with Conditional Defines.

Examples

// undefining a previously defined integers
#undef TRUE
#undef FALSE
#undef NAME_TABLE_SIZE

// undefining a previously defined string
#undef PROGRAM_VERSION

// undefining a previously defined binary bitmask
#undef ST_VBLANK

// undefining a previously defined condition control
#undef DEBUG_BUILD


 Conditional Defines

 #ifdef, #ifndef, #else, #endif

The #ifdef and #ifndef directives give the ability to control the flow of compilation. They can be used to make the compiler skip certain code and data, or only pass through certain code and data once. The #else directive allows you to have a fall through condition block for when the condition evaluates to false. Finally, each conditional define is terminated with an #endif directive.

Examples

/* if a #define DEBUG_MODE has been previously declared, then the PROGRAM_VERSION will be defined with the debug string. Otherwise, if it was not, or was undefined with the #undef directive, the PROGRAM_VERSION will be defined with the release string */
#ifdef DEBUG_MODE
  #define
PROGRAM_VERSION "Version 1.0 (Debug)"
#else
  #define
PROGRAM_VERSION "Version 1.0 (Release)"
#endif

/* To allows headers to be included in multiple files without being repeatedly parsed, the conditional define keywords can be used as well */
#ifndef THISHEADER_H
#define
THISHEADER_H
// insert header file contents here

#endif


<< Back To Index