Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   preprocessor (http://www.go4expert.com/forums/preprocessor-t29538/)

ghostrider12345 12Mar2013 11:20

preprocessor
 
Why does the following line of code generate error as " pasting / and / doesnot generate a valid preprocessing token"? Can someone please help



#define comment /##/
int main()
{
comment printf("hello");
return 0;
}

shabbir 12Mar2013 11:32

Re: preprocessor
 
Comment is /**/ and not /##/ BTW

ghostrider12345 12Mar2013 11:34

Re: preprocessor
 
Quote:

Originally Posted by shabbir (Post 99206)
Comment is /**/ and not /##/ BTW

I know that Sir this question deals with pasting / and / which surely forms a single line comment

shabbir 12Mar2013 11:48

Re: preprocessor
 
So why you think /##/ would give you output as //?

ghostrider12345 12Mar2013 11:53

Re: preprocessor
 
Its a preprocessor token pasting operator which joins its operands to make a valid token!!!

shabbir 12Mar2013 12:21

Re: preprocessor
 
http://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

It says clearly and I quote
Quote:

Keep in mind that the C preprocessor converts comments to whitespace before macros are even considered. Therefore, you cannot create a comment by concatenating `/' and `*'. You can put as much whitespace between `##' and its operands as you like, including comments, and you can put comments in arguments that will be concatenated. However, it is an error if `##' appears at either end of a macro body.

aroraaisha 15Apr2013 16:56

Re: preprocessor
 
# this is symbol of preprocessor.
Ex- #include<stdio.h>
#include<conio.h>
void main()
{
{
}
getch()
}


All times are GMT +5.5. The time now is 07:29.