gpt4 book ai didi

c - 数组语法与指针语法和代码生成?

转载 作者:太空狗 更新时间:2023-10-29 16:17:49 25 4
gpt4 key购买 nike

书中,"Understanding and Using C Pointers" by Richard Reese它在第 85 页上说,

int vector[5] = {1, 2, 3, 4, 5};

The code generated by vector[i] is different from the code generated by *(vector+i) . The notation vector[i] generates machine code that starts at location vector , moves i positions from this location, and uses its content. The notation *(vector+i) generates machine code that starts at location vector , adds i to the address, and then uses the contents at that address. While the result is the same, the generated machine code is different. This difference is rarely of significance to most programmers.

你可以看到 excerpt here .这段话是什么意思?在什么情况下,任何编译器都会为这两者生成不同的代码?从基地“移动”和“添加”到基地之间有区别吗?我无法让它在 GCC 上运行——生成不同的机器代码。

最佳答案

引用是错误的。可悲的是,这种垃圾在这十年里仍然出版。事实上,C 标准将 x[y] 定义为 *(x+y)

页面后面关于左值的部分也是完全错误的。

恕我直言,使用这本书的最佳方式是将其放入回收箱或焚烧。

关于c - 数组语法与指针语法和代码生成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51373516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com