2011-09-18 5 views
0

가능한 중복 : 얼마
C Preprocessor, Stringify the result of a macroC/C++ 매크로 평가 순서

:

#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; 
} 

결과 :

PI 
pi() 
,536,

매크로 인수에서 전처리 된 데이터 만 가져 오는 방법이 있습니까? 결과로 얻으려면

pi() 
pi() 

? 나는이 질문을 발견하지 않았습니다

: 편집

C Preprocessor, Stringify the result of a macro 복제를 ...

+0

@j_kubik을, 당신은 당신의 자신의 질문을 종료 할 수 있습니다 경우 필요. –

답변

0

다른 도우미 매크로 추가 :

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