Search code examples
cgccc-preprocessorstringification

GCC Preprocessor for inline method name


I'm working on a project where I have code like the following:

#define NAME() Array

inline NAME()* NAME()_init (void* arg0){return (NAME()*)Object_init(arg0);}

But I get the following result:

inline Array* Array _init (void* arg0){return (Array*)Object_init(arg0);}

With a space between the "Array" and the "_init" Because this is a function name, I obviously do not want the space. Does anyone know how to get the space out?


Solution

  • You should change the semantics in something like this:

    #define NAME(X) Array##X
    inline NAME()* NAME(_init) (void* arg0){return (NAME()*)Object_init(arg0);}

    EDIT: At least it works with GNU cpp.

    EDIT2: tried also with -ansi -pedantic and it seemed to work without warning...