On Sun, 2010-01-10 at 15:46 +0100, Eric Botcazou wrote:
> > The aliasing rules treat "char" specially because char is a bit like a
> > "poor main's void".
>
> Not symmetrically though, only for the type of the lvalue expression used to
> access the object (C99 6.5.7).
BTW in Ada if one uses address clause to overlay a 16 character string
and a 4 4-byte integer array (both aliased) which is then accessed what
can we expect GCC-wise? Are we safe from aliasing related optimizations?
FWIW the program below seems to work as expected.
Laurent
procedure P is
subtype String16 is String (1 .. 16);
S16 : aliased String16;
for S16'alignment use Integer'Alignment;
type Int4 is array (1 .. 4) of Integer;
I4 : aliased Int4;
for I4'Address use S16'Address;
X : constant := 1 + 256 + 256*256 + 256*256*256;
begin
S16 := (others => Character'Val (1));
if I4 /= (X, X, X, X) then
raise Program_Error;
end if;
end P;