none
Help: error C2059: syntax error : 'string' caused by a "define directive"

    Question

  • In a head file. There's line:

    #define FUNCNAME(func) static const char * __FUNCTION__ = (func);

    And the error occurs wherever such a line of code appears:

    FUNCNAME("MyClass::MyFunc");

    Any help would be very appreciated. Thank you.

    p.s. I'm working in VC2005, and it works ok in VC6 environment.
    Wednesday, December 17, 2008 2:28 PM

Answers

  • At some point, Microsoft introduced the __FUNCTION__ preprocessor macro which does pretty much exactly what your FUNCNAME macro does.  My guess is they introduced it sometime between VC6 and VC2005, hence your error -- your macro expands to something like static const char * "MyClass::MyFunc" = "MyClass::MyFunc" which doesn't make sense

    This is a good reason to avoid using identifiers that begin with underscores (or double-underscores) since they're usually reserved for the implementation.
    • Marked as answer by NEske Monday, December 22, 2008 11:58 AM
    Wednesday, December 17, 2008 6:30 PM

All replies

  • At some point, Microsoft introduced the __FUNCTION__ preprocessor macro which does pretty much exactly what your FUNCNAME macro does.  My guess is they introduced it sometime between VC6 and VC2005, hence your error -- your macro expands to something like static const char * "MyClass::MyFunc" = "MyClass::MyFunc" which doesn't make sense

    This is a good reason to avoid using identifiers that begin with underscores (or double-underscores) since they're usually reserved for the implementation.
    • Marked as answer by NEske Monday, December 22, 2008 11:58 AM
    Wednesday, December 17, 2008 6:30 PM
  • I guessed so. Thank you!
    Monday, December 22, 2008 11:58 AM