The translation of defines is done lexically and not semantically, so the compiler does not check the accuracy of the define.
The following example shows some uses of this feature:
#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:
XREF i UseI EQU i Constant EQU 1 Sum EQU Constant + $1000 + @234
The hexadecimal C constant 0x1000 was translated to $1000 while the octal 01234 was translated to @1234. In addition, the compiler has inserted one space between every two tokens. These are the only changes the compiler makes in the assembler listing for defines.
Macros with parameters, predefined macros, and macros with no defined value are not generated.
The following defines do not work or are not generated:
#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:
XREF i AddressOfI EQU & i ConstantInt EQU ( ( int ) 1 ) useUndef EQU UndefFkt * 6 Anything EQU § § / % & % / & + * % ç 65467568756 86
The AddressOfI macro does not assemble because the assembler does not know to interpret the & C address operator. Also, other C-specific operators such as dereferenciation (*ptr) must not be used. The compiler generates them into the assembler listing file without any translation.
The ConstantInt macro does not work because the assembler does not know the cast syntax and the types.
Macros with parameters are not written to the listing. Therefore, Mul7 does not occur in the listing. Also, macros defined as Nothing, with no actual value, are not generated.
The C preprocessor does not care about the syntactical content of the macro, though the assembler EQU directive does. Therefore, the compiler has no problems with the useUndef macro using the undefined object UndefFkt. The assembler EQU directive requires that all used objects are defined.
The Anything macro shows that the compiler does not care about the content of a macro. The assembler, of course, cannot treat these random characters.
These types of macros are in a header file used to generate the assembler include file. They must only be in a region started with #pragma CREATE_ASM_LISTING OFF so that the compiler will not generate anything for them.