Is it guaranteed that Complex Float variables will be 8-byte aligned in memory?

后端 未结 1 1674
生来不讨喜
生来不讨喜 2021-01-15 18:18

In C99 the new complex types were defined. I am trying to understand whether a compiler can take advantage of this knowledge in optimizing memory accesses. Are these objects

相关标签:
1条回答
  • 2021-01-15 18:59

    A float complex is guaranteed to have the same memory layout and alignment as an array of two float (§6.2.5). Exactly what that alignment will be is defined by your compiler or platform. All you can say for sure is that a float complex is at least as aligned as a float.

    if that is assumed aligned, how can one be sure that the address passed is of an actual complex and not a cast from another (non 8-aligned) type?

    If your caller passes you an insufficiently-aligned pointer, that's undefined behavior and a bug in their code (§6.3.2.3). You don't need to support that (though you may choose to).

    0 讨论(0)
提交回复
热议问题