I have the following:
#include <stdio.h>
typedef union u_data
{
struct
{
int a;
int b;
int c;
};
int elem[3];
} my_data;
int main(void)
{
my_data data;
data.a = 3;
data.b = 5;
data.c = -3;
printf("%d, %d, %d\n", data.elem[0], data.elem[1], data.elem[2]);
}
and it works as I expected with output: 3, 5, -3
however I understand that structs can have padding in them so does that mean that the elements in the struct might not always align with the array?