Compile error about MACRO

G

George2

Hello everyone,


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...

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");

	return 0;
}


thanks in advance,
George
 
I

Ian Collins

George2 said:
Hello everyone,


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...
No, a is "hello" and b is "world" so your macro produces "hello"_"world".
 
E

echo.sj

Hello everyone,

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...

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");[/QUOTE]
               ~~~~~~~~~~~~~~~~~~~~~~~~MERGE(hello,world);[QUOTE]
return 0;}

thanks in advance,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top