Is it undefined behavior to form a pointer range from a stack address?

后端 未结 6 1584
走了就别回头了
走了就别回头了 2020-12-20 15:47

Some C or C++ programmers are surprised to find out that even storing an invalid pointer is undefined behavior. However, for heap or stack arrays, it\'s okay to store the a

6条回答
  •  渐次进展
    2020-12-20 16:33

    You could define c as an array of size 1:

    char c[1] = { 'X' };

    Then the undefined behavior would become defined behavior. Resulting code should be identical.

提交回复
热议问题