jeudi 21 juillet 2016

Is there a way by which I can pass a variable list to a #define directive and cause it to replace the string value by the literal value?

e.g.:

#define TEST_RUN(_retType, _funcName,_paramList)
({
    _retType (*funcPtr)(_paramList) = _funcName;
    _retType a = funcPtr;
    std::cout << a << std::endl;
})

and I pass to this :

void someFunc(){
    std::string retType = "int";
    std::string paramList = "int, int";
    std::string funcName = foo;
    TEST_RUN(retType, funcName, paramList);
}

Function foo :

int foo( int a, int b){
    return a>b?a:b;
}

The basic idea is to reate a variable param list and return type for a function pointer for a c98 compiler

Aucun commentaire:

Enregistrer un commentaire