Re: Compile error about MACRO
- From: George <George@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 26 Nov 2007 05:22:03 -0800
Thanks Norbert,
I am using Visual Studio 2005, are there any tools or compiler option which
could see the preprocessor processing result of a source file?
regards,
George
"Norbert Unterberg" wrote:
George schrieb:.
The compile error of the following code is,
foo.cpp(7) : error C2146: syntax error : missing ';' before identifier '_'
foo.cpp(7) : error C2065: '_' : undeclared identifier
foo.cpp(7) : error C2143: syntax error : missing ';' before 'string'
I do not know why there is errors. I think in MERGE macro, the value of
parameter a is hello and the value of parameter b is world in my case, and I
defined hello_world to "H E L L O", it should be fine...
Wrong. In the MERGE macro, a is replaced by the string "hello", not the token
hello. You only use quotes in macro arguments when you want strings.
Any ideas?
[Code]
#define MERGE(a,b) a ## _ ## b
#define hello_world "H E L L O"
int foo()
{
char* p0;
p0 = MERGE("hello", "world");
This expands to:
p0 = "Hello"_"world";
which is definately a syntax error. Try:
p0 = MERGE(hello, world);
You are just experiencing the difference between a string and a token. The ##
operator works on tokens not on strings. To merge strings you do not need the ##
operator.
Norbert
- Follow-Ups:
- Re: Compile error about MACRO
- From: Igor Tandetnik
- Re: Compile error about MACRO
- References:
- Re: Compile error about MACRO
- From: Norbert Unterberg
- Re: Compile error about MACRO
- Prev by Date: How to create Word Processing from scratch?
- Next by Date: Re: Quering "System Idle Process"
- Previous by thread: Re: Compile error about MACRO
- Next by thread: Re: Compile error about MACRO
- Index(es):
Relevant Pages
|