开发者

C/C++ macro evaluation order [duplicate]

This question already has answers here: 开发者_Python百科 Closed 11 years ago.

Possible Duplicate:

C Preprocessor, Stringify the result of a macro

Shortly:

#include <iostream>

float pi(){ return 3.14; }

#define PRINT(x) std::cout << #x << std::endl;

#define PI pi()

int main(int argc, char *argv[])
{
    PRINT(PI)
    PRINT(pi())
    return 0;
}

Result:

PI
pi()

Is there any way to get only preprocessed data in macro argument? To get as a result

pi()
pi()

?

EDIT:

I haven't noticed this question: C Preprocessor, Stringify the result of a macro Duplicate...


Add another helper macro:

#define QU(x) #x
#define PRINT(x) std::cout << QU(x) << std::endl;
#define PI pi()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜