From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,953a175e642a4006 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-01-17 06:47:03 PST Path: supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!cyclone-sjo1.usenetserver.com!news-out.usenetserver.com!ptdnetP!newsgate.ptd.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.csl-gmbh.net!news-DUS.ecrc.net!news-FFM2.ecrc.net!news.iks-jena.de!lutz From: lutz@iks-jena.de (Lutz Donnerhacke) Newsgroups: comp.lang.ada Subject: Re: Memory representation of variable length record components Date: 17 Jan 2001 14:40:25 GMT Organization: IKS GmbH Jena Distribution: world Message-ID: References: NNTP-Posting-Host: taranis.iks-jena.de Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: slrn/0.9.5.7 (UNIX) Xref: supernews.google.com comp.lang.ada:4092 Date: 2001-01-17T14:40:25+00:00 List-Id: * 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.