매크로에서 ## 토근(연산자?)이 잘 이해돼지 않습니다.

dltkddyd의 이미지

매크로에서 ## 연산자가 잘 이해돼지 않습니다. 아래 매크로가 있는데,

#define hash_hash # ## #
#define mkstr(a) # a
#define in_between(a) mkstr(a)
#define join(c, d) in_between(c hash_hash d)
char p[] = join(x, y);

여기서 아래 join(x,y)의 결과가 "X ## y"와 같다는데요.

join(x, y)
in_between(x hash_hash y)
in_between(x ## y)
mkstr(x ## y)
"x ## y"

in_between(x hash_hash y)까지는 이해가 됩니다. 그러면 여기서 hash_hash는 매크로 인수도 없는데 어떻게

in_between(x ## y)가 될까요?

in_between(x # ## # y)

가 되어야 하는 것 아닌가요? 저

#define hash_hash # ## #

이 어떻게 적용되는 건가요?

mirheekl의 이미지

http://stackoverflow.com/questions/6595082/c-preprocessor-and-operators

# ...... #가 이스케이프 문자처럼 동작해서 내부를 그대로 반환한다고 하네요. ##를 그대로 사용할 수 없기 때문에 사용한 트릭이라고.

--