是否可以保证Complex Float变量在内存中对齐8字节? [英] Is it guaranteed that Complex Float variables will be 8-byte aligned in memory?
问题描述
在C99中,定义了新的复杂类型.我试图了解编译器是否可以利用此知识来优化内存访问.这些类型为complex float
的对象(A
-F
)是否保证在内存中是8字节对齐的?
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
-F
) of type complex float
guaranteed to be 8-byte aligned in memory?
#include "complex.h"
typedef complex float cfloat;
cfloat A;
cfloat B[10];
void func(cfloat C, cfloat *D)
{
cfloat E;
cfloat F[10];
}
请注意,对于D
,问题与D
指向的对象有关,而不与指针存储本身有关.而且,如果假定它是对齐的,那么如何确定传递的地址是实际的复数,而不是来自另一种(非8对齐)类型的转换?
Note that for D
, the question relates to the object pointed to by D
, not to the pointer storage itself. And, 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?
更新1:我可能在关于D
指针的最后一条评论中回答了自己. B/c无法知道将哪个地址分配给函数调用的参数,也无法保证将其对齐8.这可以通过__builtin_assumed_aligned()
函数解决.
UPDATE 1: I probably answered myself in the last comment regarding the D
pointer. B/c there is no way to know what address will be assigned to the parameter of the function call, there is no way to guarantee that it will be 8-aligned. This is solvable via the __builtin_assumed_aligned()
function.
其他变量的问题仍然悬而未决.
The question is still open for the other variables.