| 1 |
-- { dg-do run } |
| 2 |
-- { dg-options "-gnatws" } |
| 3 |
|
| 4 |
with Ada.Unchecked_Conversion; |
| 5 |
|
| 6 |
procedure Unchecked_Convert1 is |
| 7 |
|
| 8 |
type Byte is mod 2**8; |
| 9 |
|
| 10 |
type Stream is array (Natural range <>) of Byte; |
| 11 |
|
| 12 |
type Rec is record |
| 13 |
I1, I2 : Integer; |
| 14 |
end record; |
| 15 |
|
| 16 |
function Do_Sum (R : Rec) return Integer is |
| 17 |
begin |
| 18 |
return R.I1 + R.I2; |
| 19 |
end; |
| 20 |
|
| 21 |
function Sum (S : Stream) return Integer is |
| 22 |
subtype Chunk is Stream (1 .. Rec'Size / 8); |
| 23 |
function To_Chunk is new Ada.Unchecked_Conversion (Chunk, Rec); |
| 24 |
begin |
| 25 |
return Do_Sum (To_Chunk (S(S'First .. S'First + Rec'Size / 8 - 1))); |
| 26 |
end; |
| 27 |
|
| 28 |
A : Stream (1..9) := (others => 0); |
| 29 |
I : Integer; |
| 30 |
|
| 31 |
begin |
| 32 |
A (9) := 1; |
| 33 |
I := Sum (A(1..8)); |
| 34 |
end; |