Datasheet

PREPROCESSOR OPERATORS
The # (pound sign) is a preprocessor directive when it occurs as the first non-white-
space character on a line. Also, # and ## perform operator replacement and merg-
ing during the preprocessor scanning phase.
Operator #
In C preprocessor, a character sequence enclosed by quotes is considered a token
and its content is not analyzed. This means that macro names within quotes are not
expanded.
If you need an actual argument (the exact sequence of characters within quotes) as
a result of preprocessing, use the # operator in macro body. It can be placed in front
of a formal macro argument in definition in order to convert the actual argument to
a string after replacement.
For example, let’s have macro LCD_PRINT for printing variable name and value on LCD:
#define LCD_PRINT(val) Lcd_Custom_Out_Cp(#val ": "); \
Lcd_Custom_Out_Cp(IntToStr(val));
Now, the following code,
LCD_PRINT(temp)
will be preprocessed to this:
Lcd_Custom_Out_Cp("temp" ": "); Lcd_Custom_Out_Cp(IntToStr(temp));
Operator ##
Operator ## is used for token pasting. Two tokens can be pasted(merged) together
by placing ## in between them (plus optional whitespace on either side). The pre-
processor removes whitespace and ##, combining the separate tokens into one
new token. This is commonly used for constructing identifiers.
For example, see the definition of macro SPLICE for pasting two tokens into one
identifier:
#define SPLICE(x,y) x ## _ ## y
Now, the call SPLICE(cnt, 2) will expand to the identifier cnt_2.
Note
The mikroC PRO for AVR does not support the older nonportable method of token
pasting using (
l/**/r).
224
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5