16.3.1 User-Defined and Predefined Constants

H2INC translates constants from C to MASM format. For example, C symbolic constants of the form

#define CORNERS 4

are translated to MASM constants of the form

CORNERS EQU 4t

in cases where CORNERS is an integer constant or is preprocessed to an integer constant. See Section 1.2.4, “Integer Constants and Constant Expressions,” for more information on integer constants in MASM.

Summary: TEXTEQU is new to MASM 6.0.

When the defined expression evaluates to a noninteger value, such as a floating-point number or a string, H2INC defines the expression with TEXTEQU and adds angle brackets to create text macros. By default, however, these TEXTEQU expressions are not added to the include file. Set the /Ht option to tell H2INC to generate TEXTEQU expressions.

/* #define PI 3.1415 */

PI TEXTEQU <3.1415>

H2INC uses this form when the expression is anything other than a constant integer expression. H2INC does not check the constant or string for validity. For example, although the following C definitions are valid, H2INC creates invalid string equates without generating an error.

These C statements

#define INT 6

#define FOREVER for(;;)

generate these MASM statements:

INT EQU 6t

FOREVER TEXTEQU <for(;;)>

The first #define statement is invalid because INT is a MASM instruction; in MASM 6.0, instructions are reserved and cannot be used as identifiers. The for loop definition is invalid because MASM cannot assemble C code.

Summary: Predefined constants control the contents of .INC files.

You can make use of the following predefined constants in your C code to conditionally generate the code in .INC files. The predefined constants and the conditions under which they are defined are

Predefined Constant When Defined  
_H2INC Always defined  
M_I86 Always defined  
MSDOS Always defined  
_MSC_VER Defined as 600 for this release  
M_I8086 Defined if /G0 is specified  
M_I286 Defined if /G0 is not specified  
NO_EXT_KEYS Defined if /Za is specified  
_CHAR_UNSIGNED Defined if /J is specified  
M_I86SM Defined if /AS is specified  
M_I86MM Defined if /AM is specified  
M_I86CM Defined if /AC is specified  
M_I86LM Defined if /AL is specified  
M_I86HM Defined if /AH is specified  

For example, if your C header file includes definitions which are specific to the C portion of the program or otherwise are not appropriate for translation by H2INC, you can bracket the C-specific code with

#ifndef _H2INC

/* C-specific code */

#endif

In this case, only the C compiler processes the bracketed code.

The /u and /U options affect these predefined constants. The /uarg option undefines the constant specified as the argument. The /U option disables the definition of all predefined constants. Neither /u or /U affects constants defined by the /D option.

H2INC places an OPTION EXPR32 directive in the .INC file so that MASM correctly handles long integers within expressions. This means that the .INC files as well as all the .ASM files which include .INC files created with H2INC will resolve integer expressions in 32 bits instead of 16 bits.