最新的Usenet C参数 [英] Latest Usenet C Argument

查看:40
本文介绍了最新的Usenet C参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么C使用从零开始的索引?


许多人发现基于零的索引很难且不直观。为什么

不是从1开始的C开始指数?这对于

人来说会容易得多。


A.它没有。至少,它没有必要。参见ISO / IEC 9899:1999

6.5.2.1''数组下标'',它甚至没有提到基于零的

索引。索引库是实现定义的,并且通常可以通过编译器开关进行配置,有点像OPTION BASE 0 / OPTION BASE

1在各种BASIC中。

B.数组索引只是描述位于数组中第一个元素和我们希望的元素之间的

对象数量的另一种方式。访问。显然,如果我们试图访问第一个元素,

之间的对象数是0,所以使用0作为数组

索引是有意义的元素。

C.基于单一的索引导致不必要的复杂算术,特别是在处理多维数组时,b $ b。如果使用从零开始的索引,这些复杂情况将会消失。

D.以上都不是,因为......


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

Why does C use zero-based indexing?

Many people find zero-based indexing difficult and non-intuitive. Why
doesn''t C start indices from 1 instead? This would be much easier for
people.

A. It doesn''t. At least, it doesn''t have to. See ISO/IEC 9899:1999
6.5.2.1 ''Array subscripting'', which doesn''t even mention zero-based
indexing. The indexing base is implementation-defined, and is often
configurable via a compiler switch, a bit like OPTION BASE 0 / OPTION BASE
1 in various BASICs.
B. An array index is merely another way of describing the number of
objects that sit between the first element in the array and the element we
wish to access. Clearly, if we are trying to access the first element, the
number of objects between is 0, so it makes sense to use 0 as the array
index for the first element.
C. One-based indexing leads to unnecessarily complicated arithmetic,
especially when dealing with multi-dimensional arrays. These complications
just fall away into nothing if zero-based indexing is used.
D. None of the above, because...

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

推荐答案

Richard Heathfield写道:
Richard Heathfield wrote:

为什么C使用基于零的索引?


许多人发现基于零的索引很难且不直观。为什么

不是从1开始的C开始指数?这对于

人来说会容易得多。
Why does C use zero-based indexing?

Many people find zero-based indexing difficult and non-intuitive. Why
doesn''t C start indices from 1 instead? This would be much easier for
people.



< snip>

因为C中的数组访问是按指针算术完成的。如果

索引从1开始,编译器很可能需要在实现数组访问时执行

不必要的减法步骤。


C旨在处理相同类型的抽象。作为真正的机器,

和大多数硬件架构开始内存寻址为零。 C

是为了提高效率和逻辑清晰度。


我认为答案C是我选择的,如果必须这样做的话。

<snip>

Because array access in C is done in terms of pointer arithmetic. If
indexing began with 1, compilers would very likely need to do an
unnecessary subtraction step in implementing the array access.

C aims to "deal with the same sort of abstractions" as real machines,
and most hardware architectures start memory addressing at zero. C
follows this for the sake of efficiency and logical clarity.

I think answer C is the one I would choose, if I had to do so.


12月21日上午11:35,Richard Heathfield< r ... @ see.sig.invalidwrote:
On Dec 21, 11:35 am, Richard Heathfield <r...@see.sig.invalidwrote:

为什么C使用从零开始的索引?


许多人发现基于零的索引很难且不直观。为什么

不是从1开始的C开始指数?这对于

人来说会容易得多。
Why does C use zero-based indexing?

Many people find zero-based indexing difficult and non-intuitive. Why
doesn''t C start indices from 1 instead? This would be much easier for
people.



找到从零开始索引概念的人们(就像你提到的那样,它甚至不存在于
中,它的指针也是如此)应该只需要b / b
避免C.

再加上如果现在改变了,很多C程序都会破坏。

所以..无论你抱怨多少以及你赚了多少分,它都不会发生b
$ b不会发生,而不是C.

People that find the concept of "zero-based indexing" (which doesn''t
even exist in C as you mentioned, it''s pointer arith) should simply
avoid C.
Plus if that changes now, many C programs would break.
So.. no matter how much you complain and how many points you make, it
won''t happen, not in C.


vi ****** @ gmail。 com 写道:
vi******@gmail.com wrote:

12月21日上午11点35分,Richard Heathfield< r ... @ see.sig.invalidwrote:
On Dec 21, 11:35 am, Richard Heathfield <r...@see.sig.invalidwrote:

>为什么C使用从零开始的索引?

许多人发现基于零的索引很难且不直观。为什么
不能从1开始指数?这对于
人来说会容易得多。
>Why does C use zero-based indexing?

Many people find zero-based indexing difficult and non-intuitive. Why
doesn''t C start indices from 1 instead? This would be much easier for
people.



找到从零开始索引概念的人们(就像你提到的那样,它甚至不存在于
中,它的指针也是如此)应该只需要b / b
避免C.

此外,如果现在发生变化,许多C程序都会破裂。

People that find the concept of "zero-based indexing" (which doesn''t
even exist in C as you mentioned, it''s pointer arith) should simply
avoid C.
Plus if that changes now, many C programs would break.



他们会吗?如果编译器做了必要的翻译怎么办?一个

重新编译将是所有需要的。

Would they? What if the compilers did the necessary translation. A
recompile would be all that''s needed.


所以..无论你抱怨多少以及你赚了多少分,它不会发生b $ b,不会发生在C.
So.. no matter how much you complain and how many points you make, it
won''t happen, not in C.



也许你错过了树木?理查德开始这个帖子

在另一个线程中请求定期测验问题。

这是一个测验问题。他非常清楚答案[s]

他自己。

Perhaps you missed the wood for the trees? Richard started this thread
in respose to the other thread asking for regular "quiz" questions.
This is a quiz question. He is very well aware of the answer[s]
himself.


这篇关于最新的Usenet C参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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