wrote On 03/08/06 13:59,:
> Hi all,
>
> the following is a question which i found on a book,the reader is asked
> to predict the output
>
> #include<stdio.h>
>
> #define SUM(F_NAME,DATA_TYPE,L)\
> void F_NAME(DATA_TYPE x,DATA_TYPE y)\
> {\
> DATA_TYPE add;\
> add = x + y;\
> printf("The summation of "#DATA_TYPE""\
> " values is %"#L"\n",add);\
Insert a space between the L and the following ".
The sequence L"\n" is a wide string literal that
will (eventually) produce a zero-terminated array of
wide characters. This sequence is recognized during
translation phase 3; macro processing doesn't happen
until phase 4. By that time, the L is long gone so
the macro processing encounters
string_literal # wide_string_literal
.... and the error results. Separating the L from what
follows means the combination is no longer recognized
as a wide string literal, so during macro expansion
you have
string_literal # L string_literal
.... as intended.
> }
>
> void sum_int(int,int);
> void sum_float(float,float);
> int main(void)
> {
> sum_int(3,5);
> sum_float(3.1,5.3);
>
> return 0;
> }
>
> SUM(sum_int,int,d);
> SUM(sum_float,float,f);
Another improvement would be to get rid of the
semicolons in these two lines. After macro expansion
you'll have
void sum_int(...) {
...
}
;
void sum_float(...) {
...
}
;
--