K& R2 Secition 5.9 - 重大失误
我在K& R2中发现了主要的错误(这对于这里提到的几乎没用。
提到的主题)。
K& R2第5.9节指针vs 。多维阵列的开始类似于
这个...
C的新人有时会混淆
$ b $之间的差异b二维数组和一个指针数组......
然后继续解释int * b [10];是... b $ b"然而,对于b,定义只分配10个指针......假设b / b的每个元素确实指向
一个二十元素阵列,那么
将被留出200个投注,加上十个指针单元......
它只是我,或者这个解释只适用于int(* b)[10];
????
我很确定K& R2完全是这部分错了(让我困惑了
一段时间)。
后来在第5.9节,它说...到目前为止最多频繁使用
指针数组是存储不同长度的字符串......
再一次,这似乎是完全错误的。
char * strings [] = {" Bob",Dave"," Jack");
''strings''仅管理指向匿名对象的指针
由初始化自动创建(这里没有提到
)挠度)。 ''字符串''并没有打击'鲍勃' " Dave和QUOT; 杰克。
总而言之,K& R2是一本了不起的书,但是这一部分(对于初学者来说通常是最难的) )使它成为一本不那么神奇的书
(相当平均)。
我在这里,还是我错了(我很确定我'是的,但我仍然是
我不知道这些错误是如何出现在书中的,考虑到作者和作为圣经的几十年来的圣经) 。
为什么这些错误没有被发现?为什么我没有发现这些错误?我完全错了吗?
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein
mentioned topics).
K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like
this...
"Newcomers to C are somtimes confused about the difference between a
two-dimensional array and an array of pointers..."
then continues to explain int *b[10]; to be...
"For b, however, the definition only allocates 10 pointers ... Assuming
that each element of b does point to a twenty element array,then there
will be 200 ints set aside, plus ten cells for pointers... "
Is it just me, or is that explanation only valid for int (*b)[10];
????
I''m pretty sure K&R2 is totally wrong in this section (had me confused
for a while).
Later on in section 5.9, it says "... by far the most frequent use of
arrays of pointers is to store character strings of diverse lengths..."
Once again, this seems totally wrong.
char *strings[] = {"Bob","Dave","Jack");
''strings'' is only managing pointers to anonymous objects that are
automatically created by the initialization (which there is no mention
of in this section). ''strings'' doesn''t strore "Bob" "Dave" "Jack".
All in all, K&R2 has been an amazing book, but this one section (which
is often the hardest for beginners) makes it a less amazing book
(rather average).
Am I right here, or am I wrong (I''m pretty sure I''m right, but I still
don''t know how these mistakes could be in the book, considering the
authors and the many decades it has been the bible).
How come these errors weren''t caught? How come none of the errata I
have found mentions these? Am I totally wrong?
TTroy写道:
我在K& R2中发现了主要错误(这对于本文提到的主题几乎没用。)
K& R2第5.9节指针与多维数组的开头类似于
这...
C的新手对于二维数组和指针数组之间的差异感到困惑......然后继续解释int * b [10] ]。然而,对于b,定义只分配10个指针......假设b的每个元素确实指向一个二十元素数组,那么
只是我,或者说这个解释只适用于int(* b)[10];
????
这只是你;你错了。
int * b [10];
是指向int的数组[10]的声明。
int(* b)[10];
是* one *指向int数组[10]的声明。
我非常肯定K& ; R2在这部分是完全错误的(让我困惑了一段时间)。
你错了。对于那些相当确定的人来说,这种情况经常发生。一段经过大量考虑已经过了30年的文字是错误的。
后来在第5.9节中,它说......到目前为止最频繁使用指针数组来存储不同长度的字符串......
再一次,这似乎是完全错误的。
char * strings [] = {" ; Bob,Dave,杰克);
'字符串''仅管理指向由初始化自动创建的匿名对象的指针(没有提及
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein
mentioned topics).
K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like
this...
"Newcomers to C are somtimes confused about the difference between a
two-dimensional array and an array of pointers..."
then continues to explain int *b[10]; to be...
"For b, however, the definition only allocates 10 pointers ... Assuming
that each element of b does point to a twenty element array,then there
will be 200 ints set aside, plus ten cells for pointers... "
Is it just me, or is that explanation only valid for int (*b)[10];
????
It''s just you; and you are dead wrong.
int *b[10];
is the declaration for an array[10] of pointers to int.
int (*b)[10];
is the declaration for *one* pointer to an array[10] of int.
I''m pretty sure K&R2 is totally wrong in this section (had me confused
for a while).
You dead wrong. This is frequently the case for people who are "pretty
sure" that a text that has been gone over carefully for some 30 years is
wrong.
Later on in section 5.9, it says "... by far the most frequent use of
arrays of pointers is to store character strings of diverse lengths..."
Once again, this seems totally wrong.
char *strings[] = {"Bob","Dave","Jack");
''strings'' is only managing pointers to anonymous objects that are
automatically created by the initialization (which there is no mention
of in this section). ''strings'' doesn''t strore "Bob" "Dave" "Jack".
指针数组的使用是存储字符串。 ''字符串''
没有做任何事情,所以它没有存储就像它没有做的那样,它没有做到这一点积分。这是一个数组。
The use of the array of pointers is to store the strings. ''strings''
doesn''t do anything, so that it doesn''t store is beside the point as
much as that it doesn''t do integrals. It''s an array.
TTroy写道:
TTroy wrote:
我在K& R2中发现了主要的错误(这对于本文提到的主题几乎没用。)
K& R2第5.9节指针与多维数组的开头类似于
这...
C的新手对于二维数组和指针数组之间的差异感到困惑......然后继续解释int * b [10] ]。然而......对于b,定义只分配10个指针...
假设b的每个元素确实指向一个二十元素数组,那么
预留200个整数,加上10个指针单元......
只是我,或者说这个解释只适用于int(* b)[10];
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein
mentioned topics).
K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like
this...
"Newcomers to C are somtimes confused about the difference between a
two-dimensional array and an array of pointers..."
then continues to explain int *b[10]; to be...
"For b, however, the definition only allocates 10 pointers ... Assuming that each element of b does point to a twenty element array,then there will be 200 ints set aside, plus ten cells for pointers... "
Is it just me, or is that explanation only valid for int (*b)[10];
上面的
b应该是:int(* b [10])[20];
b above should be: int (*b[10])[20];
Martin Ambuhl写道:
Martin Ambuhl wrote:
TTroy写道:
我在K& R2中发现了主要的错误(这对于这里提到的
几乎没用。)
> K& R2第5.9节指针与多维数组的开始类似于
这个...
C的新手对于
a二维数组之间的差异感到困惑和一个指针数组......
然后继续解释int * b [10];然而......对于b,定义只分配10个指针...
假设b的每个元素确实指向一个二十元素数组,那么
预留200个整数,加上10个指针单元......
只是我,或者说这个解释只适用于int(* b)[10];
????
这只是你;你错了。
int * b [10];
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein mentioned topics).
K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like
this...
"Newcomers to C are somtimes confused about the difference between a two-dimensional array and an array of pointers..."
then continues to explain int *b[10]; to be...
"For b, however, the definition only allocates 10 pointers ... Assuming that each element of b does point to a twenty element array,then there will be 200 ints set aside, plus ten cells for pointers... "
Is it just me, or is that explanation only valid for int (*b)[10];
????
It''s just you; and you are dead wrong.
int *b[10];
b的每个元素都没有指向一个20元素的int数组。 b的每个
元素都指向一个int。作者应该说假设
,b的每个元素确实指向一个int,恰好是20个int数组的第一个元素。这个错误是至关重要的,因为
确实存在一些完全不同的东西,这些东西非常适合他们的不是非常准确。描述。这导致混乱。如果我指着一支
铅笔并且告诉你它是一个可以写作的工具并且它有一个永久的墨水
墨水那么那就是那个两个人的大错...
理由:我对铅笔的解释略有关闭,而且最重要的是,我的解释实际上是别的东西:
a pen。
是指向int的数组[10]的声明。
int(* b)[10];
是* one *指向int数组[10]的声明。
是的,我的意思是int(* b [10])[20];这完全符合描述。
Each element of b doesn''t point to a 20 element array of int. Each
element of b points to an int. The authors should have said "Assuming
that each element of b does point to an int which happens to be the
first element of a 20 int array." This mistake is crucial because
there really exists something totally different that fits their "not
very accurate" description. This leads to confusion. If I point at a
pencil and tell you that it''s an instrument to write with and it has
ink in it which is permanent, then that''s a big mistake for two
reasons: I''m ''slightly'' off on my explanation of the pencil, and most
importantly, my explanation is really the qualities of something else:
a pen.
is the declaration for an array[10] of pointers to int.
int (*b)[10];
is the declaration for *one* pointer to an array[10] of int.
Yeah, I meant int (*b[10])[20]; This exactly fits the description.
我非常肯定K& R2在本节中是完全错误的(有我$ b) $ b混淆了一段时间。)
I''m pretty sure K&R2 is totally wrong in this section (had me confused for a while).
你错了。
You dead wrong.
我解释了为什么我认为K& ; R2错了,但你给了
无解释来解释我为什么出错了。你所做的只是
解释上面两个定义是什么,没有将它与
任何东西联系起来。
对于那些非常确定的人来说,这种情况经常发生。一个已经过了30年b $ b的文本是错误的。
我很确定它是错的(解释是关闭 ;事实上,
但是因为它准确地描述了一些完全不同的东西,
这就是它的错误所在。
I gave an explanation as to why I thought K&R2 was wrong, but you gave
no explanation to explain why I am ''dead wrong.'' All you did was
explain what thoise two definitions above were, without relating it to
anything.
This is frequently the case for people who are "pretty
sure" that a text that has been gone over carefully for some 30 years
is wrong.
I''m pretty sure it''s wrong (the explanation is "close" to the truth,
but since it''s accurately describing something totally different,
that''s what makes it very wrong).
稍后在第5.9节中,它说...到目前为止最频繁使用
指针数组是存储多种
长度的字符串。 ..再次,这似乎是完全错误的。
char * strings [] = {" Bob",Dave,Jack";
''字符串''只管理指向由初始化自动创建的匿名对象的指针(在本节中没有提到
)。 ''字符串''并没有打击'鲍勃' " Dave和QUOT; 杰克。
指针数组的使用是存储字符串。
Later on in section 5.9, it says "... by far the most frequent use of arrays of pointers is to store character strings of diverse lengths..."
Once again, this seems totally wrong.
char *strings[] = {"Bob","Dave","Jack");
''strings'' is only managing pointers to anonymous objects that are
automatically created by the initialization (which there is no mention of in this section). ''strings'' doesn''t strore "Bob" "Dave" "Jack".
The use of the array of pointers is to store the strings.
不,它不是,并且这样想是危险的。假设您有一个
结构,如果您选择在其中包含一个
(char *)数组,并且您认为*它如果你试着把结构写到一个文件中,你会拿着字符串,你会不会遇到大麻烦。数组
指向匿名字符串对象的char指针只是
''管理'对字符串的引用(通过指向它们的第一个
$ b) $ b个字符)。
''字符串''
没有做任何事情,所以它不存储就像它那样无关紧要不做积分。这是一个数组。
No it''s not, and thinking like this is dangerous. Say you have a
structure that you want to have strings in it, if you chose to have a
(char *) array in it, and you *think* it''s holding the strings, you''ll
be in big trouble if you try to write the structure to a file. Arrays
of pointers to char that point to anonymous string objects are just
''managing'' references to the strings (by pointing to their first
characters).
''strings''
doesn''t do anything, so that it doesn''t store is beside the point as
much as that it doesn''t do integrals. It''s an array.
除了这一点?如果不是图表跟随他们的
解释,这将是一个非常危险的错误。还有
没有提到如何创建字符串或它们实际上存储的位置是什么,这使错误更加复杂。而且,
初始化定义使得它看起来像字符串
实际上也存储在数组中。
ex:
" ...到目前为止,最常使用的是
指针数组,用于存储不同长度的字符串...... ;
后跟:
char * strings [] = {" string1"," string2"," string3") ;
这可能会让很多新手读者感到困惑(这并不会让我感到困惑,但是我上面提到的错误就是b / b
)。 * *看起来像字符串是存储在数组中的字符串,上面的文献暗示存储。
加上[]数组的概念也意味着存储。还缺少
解释这些字符串的存储方式/位置也意味着它们是存储在字符串数组中的
。
所有我要求的是所有为这本
书保留勘误表的人都要考虑到这一点。
Besides the point? If it isn''t for the diagram that following their
explanation, this would been a very dangerous mistake. Also there is
no mention of how the strings are created or where they are actually
stored, which compounds the mistake. And also again, the
initialization with definition makes it look like the strings are
actually being stored in the array too.
ex:
"... by far the most frequent use of
arrays of pointers is to store character strings of diverse lengths..."
followed by:
char *strings[]= {"string1", "string2", "string3");
This might confuse very many newbie readers (it didn''t confuse me, but
the mistake I mentioned above did). It *looks* like the strings are
being stored in the array, and the literature above it implies storage.
Plus the [] array notion also implies storage. Also the lack of
explanation of how/where these strings are stored also implies they are
stored in the strings array.
All I''m requesting is all the people who maintain errata lists for this
book take this into account.