有什么用用C ## preprocessor的 [英] What is the use of ## preprocessor in C

查看:134
本文介绍了有什么用用C ## preprocessor的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  çpreprocessor和串联

任何人都可以用例子来解释?

can anybody explain with example ?

推荐答案

它允许从他们的零件构造indentifiers。例如:

It allows to construct indentifiers from their parts. Eg:

#define CLASS_NAME(name) CLASS__ ## name

将扩大 CLASS_NAME(阿尔法) CLASS__alpha 。它极大地由升压preprocessor库,例如使用技巧使用。

would expand CLASS_NAME(alpha) to CLASS__alpha. It is vastly used in tricks used by the boost preprocessor library, eg.

#define IF0(a, b) b
#define IF1(a, b) a
#define IF(cond, a, b) IF ## cond(a, b)

这将扩大 IF(0,A,B) A IF (1,A,b) b 。此外,有时,它被用来产生结构和函数名(类似于C ++模板)。

which would expand IF(0, a, b) to a and IF(1, a, b) to b. Also, sometimes, it is used to generate struct and function names (akin to c++ templates).

这篇关于有什么用用C ## preprocessor的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆