| 1 |
-- { dg-do run } |
| 2 |
-- { dg-options "-O" } |
| 3 |
|
| 4 |
with Interfaces; use Interfaces; |
| 5 |
with Unchecked_Conversion; |
| 6 |
|
| 7 |
procedure Opt31 is |
| 8 |
|
| 9 |
type Unsigned_24 is new Unsigned_32 range 0 .. 2**24 - 1; |
| 10 |
subtype Time_T is Unsigned_24 range 0 .. 24 * 60 * 60 * 128 - 1; |
| 11 |
|
| 12 |
type Messages_T is array (Positive range <>) of Unsigned_8; |
| 13 |
subtype T_3Bytes is Messages_T (1 .. 3); |
| 14 |
|
| 15 |
type Rec1 is record |
| 16 |
F : Time_T; |
| 17 |
end record; |
| 18 |
for Rec1 use record |
| 19 |
F at 0 range 0 .. 23; |
| 20 |
end record; |
| 21 |
for Rec1'Size use 24; |
| 22 |
|
| 23 |
type Rec2 is record |
| 24 |
I1,I2,I3,I4 : Integer; |
| 25 |
R1 : Rec1; |
| 26 |
end record; |
| 27 |
|
| 28 |
function Conv is new Unchecked_Conversion (T_3Bytes, Rec1); |
| 29 |
|
| 30 |
procedure Decode (M : Messages_T) is |
| 31 |
My_Rec2 : Rec2; |
| 32 |
begin |
| 33 |
My_Rec2.R1 := Conv (M (1 .. 3)); |
| 34 |
if not My_Rec2.R1.F'Valid then |
| 35 |
raise Program_Error; |
| 36 |
end if; |
| 37 |
end; |
| 38 |
|
| 39 |
Message : Messages_T (1 .. 4) := (16#18#, 16#0C#, 16#0C#, 16#18#); |
| 40 |
|
| 41 |
begin |
| 42 |
Decode (Message); |
| 43 |
end; |