使用真实和用C假 [英] Using true and false in C

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

问题描述


  1. 与布尔类型,然后从使用真假

  2. 使用preprocessor定义的#define FALSE 0 ...的#define TRUE!(FALSE)

  3. 只需直接使用常量,即1和0

是我错过了还有其他的方法?什么是不同方法的利弊?

are there other methods I missed? What are the pros and cons of the different methods?

我想最快的将是3号,2更容易阅读依然(虽然按位求反将略有增加开销),1是最可读不是所有的编译器兼容。

I suppose the fastest would be number 3, 2 is more easily readable still (although bitwise negation will slightly add to overhead), 1 is most readable not compatible with all compilers.

推荐答案

就包括< stdbool.h> 如果您的系统提供了它。这定义了许多宏,包括布尔真正(分别定义为 _Bool ,0和1)。见C99第7.16更多的细节。

Just include <stdbool.h> if your system provides it. That defines a number of macros, including bool, false, and true (defined to _Bool, 0, and 1 respectively). See section 7.16 of C99 for more details.

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

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