Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Compile error about MACRO

Reply
Thread Tools

Compile error about MACRO

 
 
George2
Guest
Posts: n/a
 
      11-26-2007
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
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      11-26-2007
George2 wrote:
> 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".

--
Ian Collins.
 
Reply With Quote
 
 
 
 
echo.sj
Guest
Posts: n/a
 
      11-26-2007
On Nov 26, 2:10 pm, George2 <(E-Mail Removed)> wrote:
> 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");
Code:
               ~~~~~~~~~~~~~~~~~~~~~~~~MERGE(hello,world);
>
>         return 0;}
>
> 

>
> thanks in advance,
> George


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compile the following source code in VC6// I have error inVC++6 but compile ok in GCC fAnSKyer C++ 2 06-07-2009 07:57 AM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
in S.E. Asia : Canon EOS 300d with 100 macro ED vs. Nikon D70 with Nikon 105 macro ? J. Cod Digital Photography 0 09-29-2004 05:46 AM
#define macro to enclose an older macro with strings Dead RAM C++ 20 07-14-2004 10:58 AM
macro name from macro? D Senthil Kumar C Programming 1 09-21-2003 07:02 PM



Advertisments