__cplusplus

1、如果一段代码是需要针对C++编写的, 可以使用该宏进行条件编译。__cplusplus的值是为了表示C++的版本。__cplusplus的类型是”long int”

2、

include

define TO_LITERAL(text) TO_LITERAL_(text)

define TO_LITERAL_(text) #text

ifndef __cplusplus

/* this translation unit is being treated as a C one */
printf(“a C program\n”);

else

// this translation unit is being treated as a C++ one
printf(“a C++ program\n__cplusplus expands to \””
TO_LITERAL(__cplusplus) “\”\n”);

endif

(void)getchar();
return 0;

}

如果没有定义__cplusplus, 那么当前源代码被当作C源代码处理。
如果定义了__cplusplus,那么当前源代码被当中C++源代码处理, 并且输出__cplusplus宏被展开后的字符串。

3、不应该依赖__cplusplus宏的值。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值