S
Shao Miller
Suppose I have type 'foo' and:
sizeof (foo) == 16
alignof (foo) == 2
Suppose I have type 'foo[1][1][1][1]' and:
sizeof (foo[1][1][1][1]) == 16
Can:
alignof (foo[1][1][1][1]) == 4
? I'd like to think not, but is it prohibited? If I do:
typedef foo bar[1][1][1][1];
bar * my_bar = malloc(sizeof *bar);
foo * my_foo = (foo *) my_bar;
certainly 'my_bar' points to an object whose alignment satisfies type
'foo'. But what about the other way around?
typedef foo bar[1][1][1][1];
foo * my_foo = malloc(sizeof *foo);
bar * my_bar = (bar *) my_foo;
'my_foo' could point to an object aligned for '2', but if the alignment
requirement for 'bar' is '4', then the behaviour is undefined.
With a size of '16', array elements would always satisfy both alignment
requirements.
My guess is that no implementation does this, but again: How about
Standard-wise?
sizeof (foo) == 16
alignof (foo) == 2
Suppose I have type 'foo[1][1][1][1]' and:
sizeof (foo[1][1][1][1]) == 16
Can:
alignof (foo[1][1][1][1]) == 4
? I'd like to think not, but is it prohibited? If I do:
typedef foo bar[1][1][1][1];
bar * my_bar = malloc(sizeof *bar);
foo * my_foo = (foo *) my_bar;
certainly 'my_bar' points to an object whose alignment satisfies type
'foo'. But what about the other way around?
typedef foo bar[1][1][1][1];
foo * my_foo = malloc(sizeof *foo);
bar * my_bar = (bar *) my_foo;
'my_foo' could point to an object aligned for '2', but if the alignment
requirement for 'bar' is '4', then the behaviour is undefined.
With a size of '16', array elements would always satisfy both alignment
requirements.
My guess is that no implementation does this, but again: How about
Standard-wise?