在C / C ++,有没有一个指令类似的#ifndef的类型定义? [英] In C/C++, is there a directive similar to #ifndef for typedefs?

查看:300
本文介绍了在C / C ++,有没有一个指令类似的#ifndef的类型定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想只定义如果没有定义它的价值,我做这样的事情:

If I want to define a value only if it is not defined, I do something like this :

#ifndef THING
#define THING OTHER_THING
#endif

如果 THING 未定义的typedef 'D标识,怎么办?我愿做这样的事情:

What if THING is a typedef'd identifier, and not defined? I would like to do something like this:

#ifntypedef thing_type
typedef uint32_t thing_type
#endif

问题的出现是因为我想检查是否有外部库已经定义的布尔的类型,但我会开到听到更广泛的解决方案。

The issue arose because I wanted to check to see if an external library has already defined the boolean type, but I'd be open to hearing a more general solution.

推荐答案

没有出现在C中没有这样的设施在+ preprocessing阶段。在马克斯能做的就是

No there is no such facility in C++ at preprocessing stage. At the max can do is

#ifndef thing_type
#define thing_type uint32_t 
#endif

虽然这不是一个很好的编码习惯,我不认为它。

Though this is not a good coding practice and I don't suggest it.

这篇关于在C / C ++,有没有一个指令类似的#ifndef的类型定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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