User manual
mikroC PRO for dsPIC
MikroElektronika
263
Preprocessor Operators
The # (pound sign) is a preprocessor directive when it occurs as the rst non-whitespace character on a line. Also, #
and ## perform operator replacement and merging 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 denition 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:
#dene LCD_PRINT(val) Lcd_Out_Cp(#val “: “); \
Lcd_Out_Cp(IntToStr(val));
Now, the following code,
LCD_PRINT(temp)
will be preprocessed to this:
Lcd_Out_Cp(“temp” “: “); Lcd_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 preprocessor removes whitespace and ##, combining the separate
tokens into one new token. This is commonly used for constructing identiers.
For example, see the denition of macro SPLICE for pasting two tokens into one identier:
#dene SPLICE(x,y) x ## _ ## y
Now, the call SPLICE(cnt, 2) will expand to the identier cnt_2.
Note: The mikroC PRO for dsPIC30/33 and PIC24 does not support the older nonportable method of token pasting
using (l/**/r).