This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ada: fix layout of packed arrays


Arnaud Charlet <charlet@ACT-Europe.FR> writes:

> procedure p is
>   type T is array (1..4) of Boolean; pragma Pack(T);
> 
>   type A is record field : T; end record;
>   type B is record field : T; end record;
>   for B use record field at 0 range 0..5; end record;
> 
>   function A_To_Byte is new Ada.Unchecked_Conversion (A, Unsigned_8);
>   function B_To_Byte is new Ada.Unchecked_Conversion (B, Unsigned_8);
> 
>   procedure TtoA (qt : in T; qa : out A) is begin qa.field := qt; end;
> 
>   procedure TtoB (qt : in T; qb : out B) is begin qb.field := qt; end;
> 
>   my_t : T := (true, true, true, false);
>   my_a : A;
>   my_b : B;
> 
> begin
>   TtoA (my_t, my_a);
>   Put ("my_a =" & Unsigned_8'Image(Shift_Right(A_To_Byte(my_a), 4)));
>   New_Line;
>   TtoB (my_t, my_b);
>   Put ("my_b =" & Unsigned_8'Image(Shift_Right(B_To_Byte(my_b), 4)));
> end;
> 
> $ gnatmake -O2 p

 To get this to compile I've had to add:

with Interfaces;
use interfaces;
with Ada.Text_IO;
use Ada.Text_IO;

 This seems to get rid of most of the problems.  It doesn't define anything
for A_To_Byte or B_To_Byte.  Where are these supposed to be defined?

 I'm using gnat 3.3 .



-- 
Thanks, Jim

http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]