Coder Social home page Coder Social logo

Comments (8)

brotherbeer avatar brotherbeer commented on July 17, 2024

“指针运算”在这里专指指针与整数的加减运算,嵌入式领域比较看重这条规则。

*p 和 p[0] 不受这条规则限制,不过可以说地更明白一些

from safe-rules.

brotherbeer avatar brotherbeer commented on July 17, 2024

未指向数组元素的指针用 p[0] 这种方式确实很怪,值得强调一下,我觉得放在这条规则里比较好。

from safe-rules.

frederick-vs-ja avatar frederick-vs-ja commented on July 17, 2024

我个人认为,如果是像我给出的示例一样,只是指针指向了一个对象(使用 new 而非 new[]),使用 *,要远好于 [0]

这在于我认为使用 []暗示这是一个“数组”,或者说这个指针指向了一片连续的内存。而 *暗示这是一个指针

new[] 时得到的结果也是指针,我们不能直接得到指代 new 表达式所创建的数组的表达式。

另外我觉得 R14.8 的标题对标准存在一些误解。在指针算术和比较中,指向非元素对象的指针被视为指向有 1 个元素的数组首元素的指针。

from safe-rules.

Mq-b avatar Mq-b commented on July 17, 2024

我个人认为,如果是像我给出的示例一样,只是指针指向了一个对象(使用 new 而非 new[]),使用 *,要远好于 [0]
这在于我认为使用 []暗示这是一个“数组”,或者说这个指针指向了一片连续的内存。而 *暗示这是一个指针

new[] 时得到的结果也是指针,我们不能直接得到指代 new 表达式所创建的数组的表达式。

我已经强调了:“暗示这是一个“数组”,或者说这个指针指向了一片连续的内存”,我知道 new[] 的结果也是指针。

from safe-rules.

Mq-b avatar Mq-b commented on July 17, 2024

“指针运算”在这里专指指针与整数的加减运算,嵌入式领域比较看重这条规则。

*p 和 p[0] 不受这条规则限制,不过可以说地更明白一些

嗯,可以强调一下。

from safe-rules.

Mq-b avatar Mq-b commented on July 17, 2024

未指向数组元素的指针用 p[0] 这种方式确实很怪,值得强调一下,我觉得放在这条规则里比较好。

都可以强调一下,因为 R14.24 就叫:“指针运算应使用数组下标的方式”,除非改一下说法。

from safe-rules.

frederick-vs-ja avatar frederick-vs-ja commented on July 17, 2024

我个人认为,如果是像我给出的示例一样,只是指针指向了一个对象(使用 new 而非 new[]),使用 *,要远好于 [0]
这在于我认为使用 []暗示这是一个“数组”,或者说这个指针指向了一片连续的内存。而 *暗示这是一个指针

new[] 时得到的结果也是指针,我们不能直接得到指代 new 表达式所创建的数组的表达式。

我已经强调了:“暗示_这是一个“数组”,或者说这个指针指向了一片连续的内存_”,我知道 new[] 的结果也是指针。

应该说这里一个数组而 p 指向数组首元素,涉及 new[] 的情况下通常不会用到指代数组的表达式。

from safe-rules.

Mq-b avatar Mq-b commented on July 17, 2024

我个人认为,如果是像我给出的示例一样,只是指针指向了一个对象(使用 new 而非 new[]),使用 *,要远好于 [0]
这在于我认为使用 []暗示这是一个“数组”,或者说这个指针指向了一片连续的内存。而 *暗示这是一个指针

new[] 时得到的结果也是指针,我们不能直接得到指代 new 表达式所创建的数组的表达式。

我已经强调了:“暗示_这是一个“数组”,或者说这个指针指向了一片连续的内存_”,我知道 new[] 的结果也是指针。

应该说这里_有_一个数组而 p 指向数组首元素,涉及 new[] 的情况下通常不会用到指代数组的表达式。

倒也不一定要是“首元素”,虽然不这样会很抽象,反正意思就这样。

from safe-rules.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.