开发者

C/C++ macro evaluation order [duplicate]

开发者 https://www.devze.com 2023-04-05 13:21 出处:网络
This question already has answers here:开发者_Python百科 Closed 11 years ago. Possible Duplicate: C Preprocessor, Stringify the result of a macro
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

精彩评论

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

关注公众号