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,e5fae12a81834f90 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-02-26 03:33:21 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!hub.org!hub.org!newsfeed.wirehub.nl!newspeer1.nac.net!news-FFM2.ecrc.net!news.iks-jena.de!lutz From: lutz@iks-jena.de (Lutz Donnerhacke) Newsgroups: comp.lang.ada Subject: Re: AdaYY wish list from current projects Date: 26 Feb 2001 11:20:24 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.6.3 (Linux) Xref: supernews.google.com comp.lang.ada:5532 Date: 2001-02-26T11:20:24+00:00 List-Id: * 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*