布尔人的缺席 [英] Absense of bool

查看:39
本文介绍了布尔人的缺席的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先:我爱C并认为它很漂亮。但是,至少有一个主要缺陷是:b $ b:缺少布尔类型。


好​​的。你们中的一些人可能会参考C99及其_Bool(无论如何,

大写''B'是什么?)以及你可以包含的标题(显然)到

得到一个真实的bool。然而,这不是我的意思 - 从一开始就应该是




Char是一个小int。我们都知道。但是,char some_bool = 0;

只是感觉不对,我认为大多数人都同意。另外,它的价格仍然太大了。


" int some_bool = 0;"是我 - 以及其他所有人,我认为 - 使用

作为bools。但是int是一个非常大的数据类型,它只会是
只有真或假(1或0)。这真的,真的让我感到烦恼。


为什么,当C设计时,他们没有看到建立一个

布尔类型的理由语言?现在重要的是,我想,但是回到

然后,应该有非常强大的技术原因。它只是

对我来说没有任何意义。


我已经问了很多人这个问题很长一段时间了,他们是/>
所有这些只是告诉我,我愚蠢地提起它。为什么?这不是我需要一个bool才能完成任何事情 - 这是原则。保存

资源和编码更美好的是一个Good Thing(TM)IMO。


所以...有人可以正确解释这个给我一次对全部?我是

确定必须有一个合乎逻辑的解释,似乎没有人真正了解b
。疯狂必须结束。


bool some_bool = 0; / *它有多棒...... * /

First of all: I love C and think that it''s beautiful. However, there is
at least one MAJOR flaw: the lack of a boolean type.

OK. Some of you might refer to C99 and its _Bool (what''s up with the
uppercase ''B'' anyway?) and the header you can include (apparently) to
get a real "bool". This isn''t my point, however -- it should have been
there from the beginning.

Char is a small int. We all know that. However, "char some_bool = 0;"
simply feels wrong, and I think that most of you agree. Plus, it''s
still too large.

"int some_bool = 0;" is what I -- and everyone else, I assume -- use
for bools. But an int is a very large data type for something that will
only ever be true or false (1 or 0). This really, really bugs me.

Why, back when C was designed, didn''t they see a reason to build in a
boolean type into the language? Now it matters less, I guess, but back
then, there should have been very strong technical reasons. It just
doesn''t make any sense whatsoever to me.

I have asked many people about this for quite some time, and they are
all just telling me that I''m silly for bringing it up. Why? It''s not
that I NEED a bool to get anything done -- it''s the principle. Saving
resources and coding a little more prettily is a Good Thing (TM) IMO.

So... can somebody properly explain this to me once and for all? I''m
sure there MUST be a logical explanation that nobody seems to really
understand. The madness must end.

bool some_bool = 0; /* How great it would be... */

推荐答案



" AommiK" < no **** @ nospam.comwrote in message

"AommiK" <no****@nospam.comwrote in message

为什么,当C设计时,他们没有看到建立一个<的理由br />
布尔类型进入语言?现在重要的是,我想,但是回到

然后,应该有非常强大的技术原因。它只是

对我来说没有任何意义。
Why, back when C was designed, didn''t they see a reason to build in a
boolean type into the language? Now it matters less, I guess, but back
then, there should have been very strong technical reasons. It just
doesn''t make any sense whatsoever to me.



C是便携式装配。通常情况下,无法使用汇编指令操作单个

位,但当然您可以使用

组合指令进行操作。

所以bool不包括在内。

我们已经开始了一点点,并且有一个很好的例子,因为

它将变量变为一个变量是标志,这通常是我们想要的。


-

免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm

C is portable assembly. Generally there is no way of manipulating single
bits with assembly instructions, though of course you can do so with a
combination of instructions.
So bool wasn''t included.
We''ve moved on a little since, and there is quite a good case for it, since
it doucments that a variable is flag, and that is frequently what we want.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


AommiK写道:
AommiK wrote:

首先:我喜欢C并认为它很漂亮。但是,有
至少有一个主要缺陷:缺少布尔类型。
First of all: I love C and think that it''s beautiful. However, there
is at least one MAJOR flaw: the lack of a boolean type.



充其量这是一个轻微的烦恼,而不是一个主要缺陷恕我直言。

At best this is a minor irritation, not a major flaw IMHO.


好​​的。你们中的一些人可能会参考C99及其_Bool(无论如何,

大写''B'是什么?)以及你可以包含的标题(显然)到

得到一个真实的bool。然而,这不是我的观点 - 它应该从一开始就是


OK. Some of you might refer to C99 and its _Bool (what''s up with the
uppercase ''B'' anyway?) and the header you can include (apparently) to
get a real "bool". This isn''t my point, however -- it should have been
there from the beginning.



在C'的大部分演变过程中,并不是一个非常需要的东西,而且仍然是

没有。

It was not a badly felt need during much of C''s evolution and still is
not.


Char是一个小int。我们都知道。但是,char some_bool = 0;

只是感觉不对,我认为大多数人都同意。另外,它的价格仍然太大了。
Char is a small int. We all know that. However, "char some_bool = 0;"
simply feels wrong, and I think that most of you agree. Plus, it''s
still too large.



使用位域。

Use bitfields.


" int some_bool = 0;"是我 - 以及其他所有人,我认为 - 使用

作为bools。但是int是一个非常大的数据类型,用于

只会是真或假(1或0)。这真的,真的让我感到烦恼。


为什么,当C设计时,他们没有看到建立一个

布尔类型的理由语言?现在重要的是,我想,但是回到

然后,应该有非常强大的技术原因。只是

对我来说没有任何意义。
"int some_bool = 0;" is what I -- and everyone else, I assume -- use
for bools. But an int is a very large data type for something that
will only ever be true or false (1 or 0). This really, really bugs me.

Why, back when C was designed, didn''t they see a reason to build in a
boolean type into the language? Now it matters less, I guess, but back
then, there should have been very strong technical reasons. It just
doesn''t make any sense whatsoever to me.



因为bool经常被高估了。在任何情况下,大多数机器都会使用打包类型的字节模拟bool。


如果你对空间感到烦恼,为什么不使用位域?

Because bool is too often an overrated type. In anycase with most
machines bool is simulated by either a byte of a packed type.

If you''re bothered about space why not use bitfields?


我已经问了很多人这个问题很长一段时间了,他们只是告诉我,我很傻提起它。为什么?这不是我需要一个bool才能完成任何事情 - 这是原则。节省

资源和更好的编码是Good Thing(TM)IMO。
I have asked many people about this for quite some time, and they are
all just telling me that I''m silly for bringing it up. Why? It''s not
that I NEED a bool to get anything done -- it''s the principle. Saving
resources and coding a little more prettily is a Good Thing (TM) IMO.



这可以做到。标准化并不重要。

This can be done. It wasn''t important enough to be Standardised.


bool some_bool = 0; / *它有多棒...... * /
bool some_bool = 0; /* How great it would be... */



你可以这样做,因为C99。

You can do this since C99.

11月3日晚上10点56分,AommiK< nos ... @ nospam.comwrote:
On Nov 3, 10:56 pm, AommiK <nos...@nospam.comwrote:

首先:我爱C并且认为这很美。但是,至少有一个主要缺陷是:
:缺少布尔类型。
First of all: I love C and think that it''s beautiful. However, there is
at least one MAJOR flaw: the lack of a boolean type.



为什么这是一个主要的缺陷?我很难看到它甚至是一个小的

缺陷。

Why is that a MAJOR flaw? I have trouble seeing it as even a minor
flaw.


好​​的。你们中的一些人可能会参考C99及其_Bool(无论如何,

大写''B'是什么?)以及你可以包含的标题(显然)到

得到一个真实的bool。然而,这不是我的观点 - 它应该从一开始就是


OK. Some of you might refer to C99 and its _Bool (what''s up with the
uppercase ''B'' anyway?) and the header you can include (apparently) to
get a real "bool". This isn''t my point, however -- it should have been
there from the beginning.



为什么?

Why?


Char是一个小int。我们都知道。但是,char some_bool = 0;

只是感觉不对,
Char is a small int. We all know that. However, "char some_bool = 0;"
simply feels wrong,



为什么?

Why?


我认为大多数人都同意。
and I think that most of you agree.



我非常怀疑。

I doubt that very much.


另外,它还是太大了。
Plus, it''s still too large.



它通常是最小的可寻址类型。如果你想要更小的

(增加更多代码来实现它的额外开销),请使用一点

字段。

It''s typically the smallest addressable type. If you want smaller
(with the added overhead of more code to implement it) use a bit
field.


" int some_bool = 0;"是我 - 以及其他所有人,我认为 - 使用

作为bools。
"int some_bool = 0;" is what I -- and everyone else, I assume -- use
for bools.



为什么你会这么想?

Why do you assume that?


但是int是一个非常大的数据类型

只有真或假(1或0)。这真的,真的让我感到烦恼。


为什么,当C设计时,他们没有看到建立一个

布尔类型的理由语言?
But an int is a very large data type for something that will
only ever be true or false (1 or 0). This really, really bugs me.

Why, back when C was designed, didn''t they see a reason to build in a
boolean type into the language?



这是一个非常愚蠢的问题。他们没有看到它的需要,因为他们没有看到它的需要。你需要解释为什么你认为他们应该看到它需要它。

That''s a very silly question. They didn''t see a need for it because
they didn''t see a need for it. You need to explain why you think they
should have seen a need for it.


现在重要的是,我猜,但是回来了

那么,应该有非常强大的技术原因。只是

对我来说没有任何意义。
Now it matters less, I guess, but back
then, there should have been very strong technical reasons. It just
doesn''t make any sense whatsoever to me.



值为零为假,非零为真。为什么你需要一个

特定的类型才能保持这个值?

A value of zero is false, non-zero is true. Why do you need a
particular type to hold the value?


我已经问了很多人这个问题很长一段时间了,他们

所有这些只是告诉我,我愚蠢地提起它。为什么?
I have asked many people about this for quite some time, and they are
all just telling me that I''m silly for bringing it up. Why?



你提起它并不一定是愚蠢的,但是你这样做是愚蠢的。你需要解释为什么你认为它是必要的,并且

为什么任何人都应该看到它的需要。你似乎认为

每个人都分享你对C及其历史的看法,并且因为某种原因与你同意。

You''re not necessarily silly for bringing it up, but you''re doing it
in a silly way. You need to explain why you think it was needed, and
why anyone should have seen a need for it. You seem to assume that
everyone shares your view of C and its history and agrees with you for
some reason.


我不需要为了完成任何工作而需要一个布尔 - 这是原则。节省

资源和更好的编码是Good Thing(TM)IMO。
It''s not
that I NEED a bool to get anything done -- it''s the principle. Saving
resources and coding a little more prettily is a Good Thing (TM) IMO.



如何节省资源?小于char的布尔类型将需要更多资源来实现和运行时。如何使编码任何更漂亮的编码?

How would it save resources? A boolean type smaller than char would
require more resources to implement and at run time. How would it make
coding any prettier?


所以...有人可以一劳永逸地向我解释这一点吗?我是

确定必须有一个合乎逻辑的解释,似乎没有人真正了解b
。疯狂必须结束。
So... can somebody properly explain this to me once and for all? I''m
sure there MUST be a logical explanation that nobody seems to really
understand. The madness must end.



我不知道你在说什么。

I''ve no idea what you''re talking about.


bool some_bool = 0 ; / *它有多棒...... * /
bool some_bool = 0; /* How great it would be... */



它在C99中存在,我认为这是毫无意义的。这种类型有什么优势

?它通过char或int给我带来了什么?

It''s there in C99, pretty pointlessly I think. What is the advantage
of this type? What does it buy me over char or int?


这篇关于布尔人的缺席的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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