From: lutz@iks-jena.de (Lutz Donnerhacke)
Subject: Re: AdaYY wish list from current projects
Date: 26 Feb 2001 11:20:24 GMT
Date: 2001-02-26T11:20:24+00:00 [thread overview]
Message-ID: <slrn99keqc.lt.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: Lwyl6.20745$5M5.1537638@news1.frmt1.sfba.home.com
* tmoran@acm.org wrote:
>What's wrong with:
> subtype String_Lengths is integer range 1 .. 32767;
> type pstring(len : String_Lengths) is record
> data : String (String_Lengths);
> end record;
> for pstring use record
> len at 0 range 0 .. 15;
> end record;
It's not portable, len should be little endian.
: raw : constant String := "\0\4Test";
: test : pstring (String_Lengths'Last);
: for test'Address use raw'Address;
warning: default initialization of "test" may modify "raw"
warning: use pragma Import for "test" to suppress initialization (RM B.1(24))
>Yes, the compiler won't do your subscript range checking for you, but
Even worse: Put_Line ("Len:" & plen'Image (test.len)); results in "Len: 1000".
And of course
Put ("Data: >");
for i in test.data'Range loop
Put (test.data(i));
end loop;
Put_Line ("<");
will print the whole 1000 chars.
>you are going to import/export this data object to a non-Ada program
>anyway.
Ok, pragma Import does suppress the initialization:
with Ada.Text_IO, System; use Ada.Text_IO;
procedure t is
subtype plen is Natural range 0 .. 1000;
type pstring (len : plen := plen'Last) is record
data : String (1 .. len);
end record;
for pstring use record
len at 0 range 0 .. 15;
end record;
for pstring'Bit_Order use System.Low_Order_First;
raw : constant String := ASCII.EOT & ASCII.NUL & "Test";
test : pstring;
for test'Address use raw'Address;
pragma Import(Ada, test);
begin
Put_Line ("Len:" & plen'Image (test.len));
Put ("Data: >");
for i in test.data'Range loop
Put (test.data(i));
end loop;
Put_Line ("<");
end t;
compiles without warning and results in:
Len: 4
Data: >Test<
Great!
Using the opposite endianess causes:
t.adb:9:11: warning: multi-byte field specified with non-standard Bit_Order
t.adb:9:11: warning: bytes are not reversed (component is little-endian)
*Barf*
next prev parent reply other threads:[~2001-02-26 11:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-02-20 20:50 AdaYY wish list from current projects Lutz Donnerhacke
2001-02-22 11:08 ` Florian Weimer
2001-02-22 13:02 ` Lutz Donnerhacke
2001-02-23 9:30 ` Florian Weimer
2001-02-23 10:12 ` Lutz Donnerhacke
2001-02-23 13:54 ` Florian Weimer
2001-02-23 14:16 ` Lutz Donnerhacke
2001-02-23 15:04 ` Florian Weimer
2001-02-23 15:15 ` Lutz Donnerhacke
2001-02-23 16:21 ` Florian Weimer
2001-02-23 16:31 ` Lutz Donnerhacke
2001-02-23 17:25 ` Florian Weimer
2001-02-26 11:22 ` Lutz Donnerhacke
2001-02-23 19:06 ` tmoran
2001-02-26 11:20 ` Lutz Donnerhacke [this message]
2001-02-23 19:06 ` tmoran
2001-02-26 11:21 ` 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