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
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).