comp.lang.ada
 help / color / mirror / Atom feed
From: Thomas Hoffmann <hoffmann@ehmgs2.et.tu-dresden.de>
Subject: Re: Need of help Leonid(dulman@ibm.net)
Date: 1997/02/10
Date: 1997-02-10T00:00:00+00:00	[thread overview]
Message-ID: <u8n2tdm68y.fsf@ehmgs2.et.tu-dresden.de> (raw)
In-Reply-To: dewar.855436299@merv


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!!!".




  reply	other threads:[~1997-02-10  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-08  0:00 Need of help Leonid(dulman@ibm.net) dulman
1997-02-08  0:00 ` Robert Dewar
1997-02-10  0:00   ` Thomas Hoffmann [this message]
1997-02-10  0:00     ` Robert Dewar
     [not found]       ` <5dpftl$qi@fozzie.sun3.iaf.nl>
1997-02-12  0:00         ` Robert Dewar
1997-02-13  0:00           ` Keith Thompson
1997-02-12  0:00     ` Rex Reges
1997-02-15  0:00       ` Keith Thompson
1997-02-17  0:00         ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox