Compile error about MACRO

Discussion in 'C Programming' started by George2, Nov 26, 2007.

  1. George2

    George2 Guest

    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
     
    George2, Nov 26, 2007
    #1
    1. Advertising

  2. George2

    Ian Collins Guest

    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.
     
    Ian Collins, Nov 26, 2007
    #2
    1. Advertising

  3. George2

    echo.sj Guest

    On Nov 26, 2:10 pm, 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...
    >
    > 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");[/color]
                   ~~~~~~~~~~~~~~~~~~~~~~~~MERGE(hello,world);[color=blue]
    >
    >         return 0;}
    >
    > 
    >
    > thanks in advance,
    > George
     
    echo.sj, Nov 26, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dead RAM
    Replies:
    20
    Views:
    1,168
    John Harrison
    Jul 14, 2004
  2. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    600
    Jack Klein
    Sep 21, 2003
  3. sounak

    to get macro name from macro value

    sounak, Nov 22, 2005, in forum: C Programming
    Replies:
    17
    Views:
    522
    Mark McIntyre
    Nov 22, 2005
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    500
    Patrick Kowalzick
    Mar 14, 2006
  5. Nagaraj
    Replies:
    1
    Views:
    913
    Lionel B
    Mar 1, 2007
Loading...

Share This Page