comp.lang.ada
 help / color / mirror / Atom feed
From: lutz@iks-jena.de (Lutz Donnerhacke)
Subject: Re: Memory representation of variable length record components
Date: 17 Jan 2001 14:40:25 GMT
Date: 2001-01-17T14:40:25+00:00	[thread overview]
Message-ID: <slrn96bbhm.18v.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: slrn96b0tc.18v.lutz@taranis.iks-jena.de

* Lutz Donnerhacke wrote:
>Easy question: How to map a IP structure to a given memory location?
>*grin*
>Easier question: How to map a Pascal string ...

Really easy:
with Ada.Text_IO, System.Address_To_Access_Conversions;
use  Ada.Text_IO;

procedure t is
   subtype Length is Natural range 0 .. 255;
   
   type pstring (len : Length) is record
      s : String (1 .. len);
   end record;
   
   pragma Pack (pstring);
   
   ps1   : pstring (1);
   ps100 : aliased pstring (100);
   
   type pstring_ptr is access all pstring;
   pa100 : pstring_ptr := ps100'Access;
   
   package C is new System.Address_To_Access_Conversions (pstring);
   pa1   : C.Object_Pointer := C.To_Pointer (ps1'Address);
   
   raw : String (1 .. 6) := Character'Val (5) & "Hello";
   praw : C.Object_Pointer := C.To_Pointer (raw'Address);
begin
   Put_Line ("ps1"   & Natural'Image (ps1'Size));
   Put_Line ("ps100" & Natural'Image (ps100'Size));
   Put_Line ("pa100" & Natural'Image (pa100.all'Size));
   Put_Line ("pa1"   & Natural'Image (pa1.all'Size));
   Put_Line ("praw" & Natural'Image (praw.all'Size) & praw.s);
   for i in Character'Val (0) .. Character'Val (10) loop
      raw (raw'First) := i;
      Put_Line ("praw" & Natural'Image (praw.all'Size) &
                         Natural'Image (praw.len) &
                         Natural'Image (praw.s'Length));
   end loop;
end t;

Now I only need to know how to use representation clauses with an unusual
discriminat depended memory layout.



  reply	other threads:[~2001-01-17 14:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-17 11:38 Memory representation of variable length record components Lutz Donnerhacke
2001-01-17 14:40 ` Lutz Donnerhacke [this message]
2001-01-17 22:58 ` Nick Roberts
2001-01-18  8:45   ` Lutz Donnerhacke
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox