Macros

The Compiler translates defines lexically and not semantically. The compiler does not check the accuracy of the define. The following example shows some uses of this feature:

Listing: Example Source Code
#pragma CREATE_ASM_LISTING ON 
int i;

#define UseI i

#define Constant 1

#define Sum Constant+0X1000+01234

The source code in the above listing produces the following output:

Listing: Output
                        XREF  i
UseI                    EQU   i

Constant                EQU   1

Sum                        EQU   Constant + $1000 + @234

Disassembly translates the hexadecimal C constant 0x1000 to $1000 and translates the octal 01234 to @1234. In addition, the compiler inserts one space between every two tokens. The Compiler makes no other changes in the assembler listing for defines.

Some macros compile but do not assemble. The Compiler compiles macros with parameters, predefined macros, and macros with no defined value, but the assembler produces no output for these macros. Although these macros are in the header file the Compiler uses to generate the assembler include file, locate the macros together and preface the section with #pragma CREATE_ASM_LISTING OFF, to prevent the compiler from generating the assembly listing.

The following defines do not work or are not generated:

Listing: Improper Defines
#pragma CREATE_ASM_LISTING ON 
int i;

#define AddressOfI &i

#define ConstantInt ((int)1)

#define Mul7(a) a*7

#define Nothing

#define useUndef UndefFkt*6

#define Anything § § / % & % / &  + * % ç 65467568756 86

The source code in the above listing produces the following output.

Listing: Output


                        XREF  i
AddressOfI              EQU   & i

ConstantInt             EQU   ( ( int ) 1 )

useUndef                EQU   UndefFkt * 6

Anything                   EQU   § § / % & % / & + * % ç 65467568756 86

The assembler does not assemble the AddressOfI macro because the assembler cannot interpret the & C address operator. Also, do not use other C-specific operators such as dereferenciation (*ptr). The compiler generates them into the assembler listing file without any translation.

The ConstantInt macro does not assemble because the assembler does not know the cast syntax and the types. The assembler does not write macros with parameters (such as Mu17) or macros with no actual value to the listing.

The C preprocessor ignores the syntactical content of the macro, therefore the compiler processes macros like useUndef, with the undefined object UndefFkt, correctly. The assembler EQU directive requires definitions for all used objects.

The Compiler processes the Anything macro in the previous listing with no difficulty. The assembler cannot process these random characters.