C相反数组索引 [英] C negative array index

查看:110
本文介绍了C相反数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的结构:

struct Node {
    struct Node* data;
    struct Node* links[4];
}

假设没有填充,确实节点 - >链接[-1] 保证要在节点::数据指向

推荐答案

没有保障;这是未定义的行为:

No guarantee; this is undefined behaviour:


  • 编译器相关的结构填充

  • 标准只定义0和长度的数组索引(含)

  • 可能严格走样违反

  • Compiler-dependent structure padding
  • Standard only defines array indexing between 0 and length (inclusive)
  • Possible strict-aliasing violation

在实践中,很可能是你最终会在数据指指点点,但任何企图访问它会导致UB。

In practice, it's quite possible that you will end up pointing at data, but any attempts to access it will result in UB.

这篇关于C相反数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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