Thread: Compile error about MACRO

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    Compile error about MACRO

    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

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 08:20 AM
  2. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  3. open scene graph compile issues
    By ichijoji in forum Game Programming
    Replies: 1
    Last Post: 08-04-2005, 12:31 PM
  4. compile program?
    By Goosie in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2005, 02:26 PM
  5. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 02:58 PM