[llvm-dev] Does an array and homogeneous struct have the same layout?
edA-qa mort-ora-y via llvm-dev
llvm-dev at lists.llvm.org
Sun Apr 8 02:46:55 PDT 2018
Does an array of a value type and a structure containing only that type
have the same alignment requirements? That is, in C-syntax:
float* array;
struct point { float x; float y; }
point p;
array = (float*)&p;
Does `array[0]` now refer to x, and `array[1]` to y?
I'm creating these structures in LLVM with default packing
(StructType::isPacked == false). I have a library that takes simple
arrays for point structs (OpenGL) and would like to layer nicer types on
top. I'm reasonably certain the above holds true, but want to
double-check that it's guaranteed.
I'd also be doing this type of operation to refer to a list of points:
point* p = ...;
array = (float*)p;
--
edA-qa mort-ora-y
http://mortoray.com/
Creator of the Leaf language
http://leaflang.org/
Streaming algorithms, AI, and design on Twitch
https://www.twitch.tv/mortoray
Twitter
edaqa
More information about the llvm-dev
mailing list