C / C ++里面的#define宏宏? [英] C/C++ #define Macro inside macro?

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

问题描述

我想是这样的:

 的#define C_OR_CPP(C__,CPP__)的#ifdef __cplusplus \\
CPP __ \\
#其他\\
C__\\
#万一

这可能吗?
也许有些肮脏的黑客用#include?

原因:
我做凡结构使用类型矢量&lt的成员变量的头部;东西> * ,但在C我希望它仅仅是无效* ,你懂的。

TIA


解决方案

什么是与问题

 的#ifdef __cplusplus
#定义C_OR_CPP(C,CPP)CPP
#其他
#定义C_OR_CPP(C,CPP)C
#万一

(离开与双下划线的名称,每phresnel此言实现)

I would like something like:

#define C_OR_CPP(C__, CPP__) #ifdef __cplusplus\
CPP__\
#else\
C__\
#endif

Is it possible? Maybe some dirty hack with #include ?

Reason: I make a header where a struct uses a member variable of type vector<stuff>*, but in C i want it to simply be void*, you know.

TIA

解决方案

What's the problem with

#ifdef __cplusplus
#define C_OR_CPP(C, CPP) CPP
#else
#define C_OR_CPP(C, CPP) C
#endif

(Leaving names with double underscore to the implementation per phresnel remark)

这篇关于C / C ++里面的#define宏宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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