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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,35ee0472de38e833 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-13 12:41:10 PST Path: supernews.google.com!sn-xit-02!supernews.com!newsfeed.online.be!oleane.net!oleane!freenix!enst!enst.fr!not-for-mail From: "Beard, Frank" Newsgroups: comp.lang.ada Subject: RE: Variable length raw-byte data Date: Wed, 13 Dec 2000 15:39:32 -0500 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: avanie.enst.fr 976740069 15403 137.194.161.2 (13 Dec 2000 20:41:09 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Wed, 13 Dec 2000 20:41:09 +0000 (UTC) To: "'comp.lang.ada@ada.eu.org'" Return-Path: X-Mailer: Internet Mail Service (5.5.2448.0) Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0beta5 Precedence: bulk List-Id: comp.lang.ada mail<->news gateway Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: supernews.google.com comp.lang.ada:3091 Date: 2000-12-13T15:39:32-05:00 -----Original Message----- From: Robert Dewar [mailto:robert_dewar@my-deja.com] > Of *course* you never allocate an instance of a > big array. in fact it is not a bad idea to add Allocate was a bad choice of words. But you missed my real point. My biggest concern is that by doing this: type byte is mod 2 ** 8; type memory is array (natural) of byte; type memptr is access memory; myMemory : memptr; You are telling the compiler that you're pointing at a 2GB array and depending on the programmer to be "kind" and use the length returned (smacks way too much of C/C++), instead of letting the language tell you when you've over-reached your bounds. What if the programmer inadvertently uses "myMemory.all'last"? If you use the constrained sub-type approach, you can still use 'first and 'last, and it properly sets the state data of the access type. Of course the counter-danger is that the programmer will inadvertently uncheck convert something using the unconstrained type instead of the constrained subtype. Which will likely lead to peculiar behavior. Another approach is to do the following: type Byte is mod 2**8; buffer_Address : System.Address; begin ... status := Get_C_Stuff(length => length, buffer_Address => buffer_Address); if (length > 0) then declare type Byte_Array is Byte_Array(1..length) of Byte; type Byte_Array_Pointer is access Byte_Array; buffer_Pointer : Byte_Array_Pointer; function To_Buffer_Pointer is new Ada.Unchecked_Conversion(System.Address,Byte_Array); begin buffer_Pointer := To_Buffer_Pointer(buffer_Address); end; ... end if; ... This is fine so long as everything you need to do is within the declare block. Every system I've worked on, both the unconstrained subtype and the declare type have worked fine. The DEC VAX Ada compiler would let you do unchecked conversion with unconstrained types, other compilers require constrained types. What's the rule in Ada 95? Does the language require both types to be constrained? Frank