您对常见问题部分的看法。 [英] Your view of FAQ section.

查看:44
本文介绍了您对常见问题部分的看法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



最重复的指示之一是

http://c-faq.com/aryptr/aryptr2.html

讨论指针和数组以及微妙的差异


char a [] =" hello";

char * p =" world";


现在,我的问题是 - 您对FAQ

描述编译器工作方式的看法如何?我们现在已经指针和数组

可能会或可能不会以不同的方式编译,可能会或可能不会更高效

,这取决于目标HW。


但是,常见问题解答中是否真的详细介绍了编译器如何计算元素地址?


例如


,----

|有用的是认识到像x [3]这样的引用根据x是数组还是指针生成不同的代码。鉴于上面的声明,当编译器

|看到表达式a [3],它发出的代码从位置a开始,移动三个,然后在那里取出字符。当它看到表达式p [3]时,它将代码发送到

|从位置p开始,在那里获取指针值,向指针添加三个,最后获取指向的字符。换句话说,[3]是过去的三个地方

| (开头)名为a的对象,而p [3]是p指向的对象的三个位置。在上面的例子中,[3]和p [3]碰巧都是'l'字符,但是

|编译器以不同的方式实现。 (本质区别在于,无论是否出现在

|表达式中,像a和p这样的指针的值都会以不同的方式计算,无论是否在下标中,如问题6.3中进一步解释的那样。 。)另见问题1.32。

` ----


One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?

e.g

,----
| It is useful to realize that a reference like x[3] generates different code depending on whether x is an array or a pointer. Given the declarations above, when the compiler
| sees the expression a[3], it emits code to start at the location ``a'''', move three past it, and fetch the character there. When it sees the expression p[3], it emits code to
| start at the location ``p'''', fetch the pointer value there, add three to the pointer, and finally fetch the character pointed to. In other words, a[3] is three places past
| (the start of) the object named a, while p[3] is three places past the object pointed to by p. In the example above, both a[3] and p[3] happen to be the character ''l'', but
| the compiler gets there differently. (The essential difference is that the values of an array like a and a pointer like p are computed differently whenever they appear in
| expressions, whether or not they are being subscripted, as explained further in question 6.3.) See also question 1.32.
`----

推荐答案

Richard< rg * ***@gmail.com写:
Richard <rg****@gmail.comwrites:

最重复的指针之一是

http://c-faq.com/aryptr/aryptr2.html


讨论了指针和数组以及它们之间的细微差别


char a [] =" hello";

char * p ="世界" ;;


现在,我的问题是这样的 - 您对FAQ

描述编译器工作方式的看法如何?我们现在已经指针和数组

可能会或可能不会以不同的方式编译,可能会或可能不会更高效

,这取决于目标HW。


但是,FAQ是否应该详细介绍编译器如何计算元素地址?
One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?



是的。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

"我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

Yes.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


Keith Thompson< ks ***@mib.orgwrites:
Keith Thompson <ks***@mib.orgwrites:

Richard< rg **** @ gmail.comwrites:
Richard <rg****@gmail.comwrites:

>最重复的指针之一是

http://c-faq.com/aryptr/aryptr2.html

讨论指针和数组以及

char之间的细微差别a [] =" hello";
char * p =" world";

现在,我的问题是这样的 - 你对FAQ的方式感觉如何
描述编译器工作。我们现在已经指针和数组可能会或者可能不会以不同的方式进行编译,并且可能会或者可能不会比目标硬件更高效。

详细了解编译器如何计算元素地址?
>One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?



是的。


Yes.



你能解释一下原因吗?


标准是否规定了编译器必须如何生成地址?

Can you explain why?

Does the standard stipulate how the compiler must generate the addresses?


Richard< rg **** @ gmail.comwrites:
Richard <rg****@gmail.comwrites:

Keith Thompson< ks *** @ mib。 orgwrites:
Keith Thompson <ks***@mib.orgwrites:

> Richard< rg **** @ gmail.comwrites:
>Richard <rg****@gmail.comwrites:

> ;>最重复的指针之一是

http://c-faq.com/aryptr/aryptr2.html

讨论了指针和数组以及它们之间的微妙差异。 ] =" hello";
char * p =" world";

现在,我的问题是这样的 - 您对FAQ的描述方式感觉如何?编译工作。我们现在已经指针和数组可能会或者可能不会以不同的方式进行编译,并且可能会或者可能不会比目标硬件更高效。

详细了解编译器如何计算元素地址?
>>One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?


是的。


Yes.



你能解释一下原因吗?


标准是否规定了编译器必须如何生成地址?


Can you explain why?

Does the standard stipulate how the compiler must generate the addresses?



好​​的,这太过简洁了。但FAQ并没有真正谈论

生成的代码;它更多地描述了

抽象机器中发生的事情,这对理解

代码的实际含义非常重要。


你有更好的方法来描述[3]和

p之间的区别[3](其中a是数组对象,p是指针对象)? br />

-

Keith Thompson(The_Other_Keith) ks *** @ mib。 org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

Ok, that was overly terse. But the FAQ doesn''t really talk about
generated code; it''s more of a description of what happens in the
abstract machine, which is important to an understanding of what the
code actually means.

Do you have a better way to describe the difference between a[3] and
p[3] (where a is an array object and p is a pointer object)?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


这篇关于您对常见问题部分的看法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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