0

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;
}
3
Contributors
3
Replies
26
Views
4 Years
Discussion Span
Last Post by deceptikon
0

Because it's illegal in C. This has been answered for you in other forums already, in detail.

0

@Adak I dont think so its illegal in C infact the "##" is a valid token pasting operator for preprocessor.The answer to this is that comments are replaced by preprocessor into white spaces before the macros are even seen!!

0

The answer to this is that comments are replaced by preprocessor into white spaces before the macros are even seen!!

That's correct. It's not the macro itself that's wrong, it's how you were using it on the assumption that it would start a comment. For example:

#include <stdio.h>

#define STR_VAL(x) #x
#define STR(x)     STR_VAL(x)

#define comment /##/

int main(void)
{
    printf("'%s'\n", STR(comment));
    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.