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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56760b0ebeac6ba1 X-Google-Attributes: gid103376,public From: Thomas Hoffmann Subject: Re: Need of help Leonid(dulman@ibm.net) Date: 1997/02/10 Message-ID: #1/1 X-Deja-AN: 217749748 references: <5dhbjt$hbe@news.ibm.net.il> organization: TU Dresden (URZ) newsgroups: comp.lang.ada Date: 1997-02-10T00:00:00+00:00 List-Id: dewar@merv.cs.nyu.edu (Robert Dewar) writes: > > Leonid asked > > << Need of help. > I am tried to work with GNAT 3.09 OS/2 in PM mode but get > message : > > raised STORAGE_ERROR > > In GNAT 3.05 I have no such problem (I tested working programs) . > > Thanks Leonid(dulman@ibm.net)>> Just a wild guess: As I played around with Leonid Dulman's code snippets for OS/2 I was hit by a similar (the same?) error. I could track this error (using a default discriminant), the explaination can be found in the Ada Programmer's FAQ (http://www.adahome.com/FAQ/programming.html#default_discr): 3.10: Why is an exception raised when giving a default discriminant? Let's assume you would like to model varying-length strings: type V_String (Size : Natural := 0) is record S : String (1 .. Size); end record; (from Robert Dewar) When you give a default discriminant, then one method (I actually think it is the preferred method) of implementation is to allocate the maximum possible length. Since your discriminant is of type Natural, this clearly won't work! GNAT may compile it, but it won't run it, and indeed I consider it a GNAT bug (on the todo list) that no warning is issued at compile time for this misuse. Some compilers, notably Alsys and RR, have at least partially "solved" this problem by introducing hidden pointers, but this to me is an undesirable implementation choice. First, it means there is hidden heap activity, which seems undesirable. In a language where pointers are explicit, it is generally a good idea if allocation is also explicit, and certainly for real-time work, hidden anything is worrisome. Second, it is not easy to do uniformly. Alsys ends up introducing arbitrary restrictions on the composition of such types (try making an array of them), and RR introduces non-contiguous representations, which are legal but troublesome. To "solve" the problem yourself, just declare a reasonable maximum length, and use a subtype representing this length as the subtype of the discriminant: Max_Length : constant := 200; subtype Index is Natural range 0 .. Max_Length; type V_String (Size : Index := 0) is record S : String (1 .. Size); end record; GNAT 3.09 issues a warning during the compiler run. -- ============================================================================= Thomas Hoffmann, Institut fuer Halbleiter- und Mikrosystemtechnik, TU Dresden E-mail: hoffmann@ehmgs2.et.tu-dresden.de If OS/2 could 'walk on water' the front page headline in InfoWorld would read "OS/2 CAN'T SWIM!!!".