What does ## mean for the C(C++) preprocessor?

余生长醉 提交于 2019-11-26 17:59:08

nothing too fancy: ## tells the preprocessor to concatenate the left and right sides

see http://en.wikipedia.org/wiki/C_preprocessor#Token_concatenation

because ## is a token concatenation operator for the c preprocessor.

Or maybe I don't understand the question.

## is Token Pasting Operator

The double-number-sign or "token-pasting" operator (##), which is sometimes called the "merging" operator, is used in both object-like and function-like macros. It permits separate tokens to be joined into a single token and therefore cannot be the first or last token in the macro definition.

If a formal parameter in a macro definition is preceded or followed by the token-pasting operator, the formal parameter is immediately replaced by the unexpanded actual argument. Macro expansion is not performed on the argument prior to replacement.

SHANAVAS P

#define f(g,g2) g##g2

## is usued to concatenate two macros in c-preprocessor. So before compiling f(var,12) should replace by the preprocessor with var12 and hence you got the output.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!