comp.lang.ada
 help / color / mirror / Atom feed
* Re: Need of help Leonid(dulman@ibm.net)
  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
  0 siblings, 1 reply; 9+ messages in thread
From: Robert Dewar @ 1997-02-08  0:00 UTC (permalink / raw)



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)>>

First, wherever you post a question like this, it is a good idea to post
more information, it is impossible to tell what might be happening from
your description. You do not even say if this is a runtime error or a
compile time error. Likely the former, in which case, it is impossible
to guess what might be wrong without code. You might try seeing if anyone
on chat@gnat.com has some ideas.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Need of help Leonid(dulman@ibm.net)
@ 1997-02-08  0:00 dulman
  1997-02-08  0:00 ` Robert Dewar
  0 siblings, 1 reply; 9+ messages in thread
From: dulman @ 1997-02-08  0:00 UTC (permalink / raw)



 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)





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Need of help Leonid(dulman@ibm.net)
  1997-02-08  0:00 ` Robert Dewar
@ 1997-02-10  0:00   ` Thomas Hoffmann
  1997-02-10  0:00     ` Robert Dewar
  1997-02-12  0:00     ` Rex Reges
  0 siblings, 2 replies; 9+ messages in thread
From: Thomas Hoffmann @ 1997-02-10  0:00 UTC (permalink / raw)



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




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Need of help Leonid(dulman@ibm.net)
  1997-02-10  0:00   ` Thomas Hoffmann
@ 1997-02-10  0:00     ` Robert Dewar
       [not found]       ` <5dpftl$qi@fozzie.sun3.iaf.nl>
  1997-02-12  0:00     ` Rex Reges
  1 sibling, 1 reply; 9+ messages in thread
From: Robert Dewar @ 1997-02-10  0:00 UTC (permalink / raw)



Thomas Hoffman says, quoting me writing about default discriminants

<<GNAT may compile it, but it won't run it, and indeed I consider it a GNAT bug (o
n the todo list) that no
warning is issued at compile time for this misuse.
>>


Robert notes:

This is a truly ancient piece of text that Thomas dug up :-)
Anyway, GNAT now gives this warning, and has for some time:

     1. procedure j is
     2.   type x (m : natural := 0) is record
     3.      s : string (1 .. m);
                              |
        >>> warning: creation of object of this type may raise Storage_Error

     4.   end record;
     5.   g : x;
          |
        >>> warning: Storage_Error will be raised at run-time

     6. begin
     7.    null;
     8. end;





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Need of help Leonid(dulman@ibm.net)
  1997-02-10  0:00   ` Thomas Hoffmann
  1997-02-10  0:00     ` Robert Dewar
@ 1997-02-12  0:00     ` Rex Reges
  1997-02-15  0:00       ` Keith Thompson
  1 sibling, 1 reply; 9+ messages in thread
From: Rex Reges @ 1997-02-12  0:00 UTC (permalink / raw)



Thomas Hoffmann wrote:

... deleted comments about types with large discriminant ranges ...

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

I think it is a bad idea to have a warning issued for this example.
Even if warnings can be suppressed or ignored, it generally takes
a written description in the comments and approval by Quality
Assurance to do so.  

I have used the V_String in the form of a generic package with 
the Max_Length as the parameter.  This allows the creation
of necessary functions as well: catenation of V_String and
V_String, catenation of String and V_String, etc.  

From the V_String package I instantiate three versions: 

    Small_Variable_Length_String
   Medium_Variable_Length_String
    Large_Variable_Length_String

I would be unhappy trying to explain why the basis for most string
storage causes compiler warnings.

An interesting problem occurred while trying to provide the 
utility functions.  I had the following function:

function V_String_Of( Standard_String : in   String )
         return                            V_String is
begin

   -- Test omitted for Strings that are too large to fit.

   return ( Size => Standard_String'Length ,
            S    => Standard_String        ) ;

end V_String_Of ;


I liked this code because it did not require creating a 
temporary variable on the stack, particularly if the string
was very large.  However, it failed whenever a substring
was passed which had a starting index other than 1:

   My_V_String := V_String_Of( "abcdefg"(2:3) );   -- Not sure this
syntax
                                                   -- is allowed but you
get
                                                   -- the point.

The aggregation mechanism will not shift the indices, but the 
assignment operator will.  Therefore, I was forced to rewrite the
function using a temporary value on the stack:


function V_String_Of( Standard_String : in   String )
         return                            V_String is

   Temp_String :  String( 1..Standard_String'Length ) 
               := Standard_String                   ;

begin

   -- Test omitted for Strings that are too large to fit.

   return ( Size => Temp_String'Length ,
            S    => Temp_String        ) ;

end V_String_Of ;


Another mechanism which causes an invisible temp variable is 
to use the string catenation function to shift the indices.


function V_String_Of( Standard_String : in   String )
         return                            V_String is
begin

   -- Test omitted for Strings that are too large to fit.

   return ( Size => Standard_String'Length ,
            S    => "" & Standard_String   ) ;

end V_String_Of ;

Both of these have the potential of blowing out the stack for large
strings, particularly in tasks with small stack allocations.



-- 
Rex Reges                      or you can call me The Fixer 
Systems Analyst                or you can call me The Lawyer
Lockheed Martin, M&DS          or you can call me The Doctor
(610)354-5047                  or you can call me Rexasaurus




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Need of help Leonid(dulman@ibm.net)
       [not found]       ` <5dpftl$qi@fozzie.sun3.iaf.nl>
@ 1997-02-12  0:00         ` Robert Dewar
  1997-02-13  0:00           ` Keith Thompson
  0 siblings, 1 reply; 9+ messages in thread
From: Robert Dewar @ 1997-02-12  0:00 UTC (permalink / raw)



Geert said

<<Of course when this package is instantiated with a 32-bit integer type
it doesn't make sense to use the full set on many machines, but IMHO it
is fine to instantiate the package. Only when a program uses operations
on Set from the instantiated generic a warning should be given.
>>

Well a general point on warnings is that they are warnings and not errors
precisely because you can't be sure they are errors. I disagree that the
warning in the generic case is inappropriate. If you create this
instantiation, it is useful to know that it may have limited use AT THE
TIME YOU CREATE IT, not later when you instantiate it.

You can always use pragma Warnings (Off) before the particular declaration
and pragma Warnings (On) after it to kill a specific warning.

You can never satisfy everyone with warnings, since some people want to be
warned more than others :-)





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Need of help Leonid(dulman@ibm.net)
  1997-02-12  0:00         ` Robert Dewar
@ 1997-02-13  0:00           ` Keith Thompson
  0 siblings, 0 replies; 9+ messages in thread
From: Keith Thompson @ 1997-02-13  0:00 UTC (permalink / raw)



In <dewar.855750810@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
[...]
> You can always use pragma Warnings (Off) before the particular declaration
> and pragma Warnings (On) after it to kill a specific warning.

Only if you happen to be using GNAT; the Warnings pragma is GNAT-specific.
If you're using a compiler that doesn't support it, you'll also get
warnings on the pragmas themselves.

-- 
Keith Thompson (The_Other_Keith) kst@aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706
Antimatter is not a condiment.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Need of help Leonid(dulman@ibm.net)
  1997-02-12  0:00     ` Rex Reges
@ 1997-02-15  0:00       ` Keith Thompson
  1997-02-17  0:00         ` Robert Dewar
  0 siblings, 1 reply; 9+ messages in thread
From: Keith Thompson @ 1997-02-15  0:00 UTC (permalink / raw)



In <3302387F.16BB@mds.lmco.com> Rex Reges <reges@mds.lmco.com> writes:
[...]
> An interesting problem occurred while trying to provide the 
> utility functions.  I had the following function:
> 
> function V_String_Of( Standard_String : in   String )
>          return                            V_String is
> begin
> 
>    -- Test omitted for Strings that are too large to fit.
> 
>    return ( Size => Standard_String'Length ,
>             S    => Standard_String        ) ;
> 
> end V_String_Of ;
> 
> 
> I liked this code because it did not require creating a 
> temporary variable on the stack, particularly if the string
> was very large.  However, it failed whenever a substring
> was passed which had a starting index other than 1:
[...]

Try this:

   function V_String_Of( Standard_String : in   String )
            return                            V_String is
      subtype Constrained_Result is String(1 .. Standard_String'Length);
   begin
    
      -- Test omitted for Strings that are too large to fit.
    
      return ( Size => Standard_String'Length ,
               S    => Constrained_Result(Standard_String) );
    
   end V_String_Of;

Note that the expression for S has to be a conversion, not a qualified
expression.

-- 
Keith Thompson (The_Other_Keith) kst@aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706
Antimatter is not a condiment.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Need of help Leonid(dulman@ibm.net)
  1997-02-15  0:00       ` Keith Thompson
@ 1997-02-17  0:00         ` Robert Dewar
  0 siblings, 0 replies; 9+ messages in thread
From: Robert Dewar @ 1997-02-17  0:00 UTC (permalink / raw)



Rex said

<<An interesting problem occurred while trying to provide the
utility functions.  I had the following function:

function V_String_Of( Standard_String : in   String )
         return                            V_String is
begin

   -- Test omitted for Strings that are too large to fit.

   return ( Size => Standard_String'Length ,
            S    => Standard_String        ) ;

end V_String_Of ;


I liked this code because it did not require creating a
temporary variable on the stack, particularly if the string
was very large.  However, it failed whenever a substring
was passed which had a starting index other than 1:>>


What makes you think that this code will not require a temporary variable
on the stack? Just because you don't see it in the source, does not mean
it is not there. Of course compilers will differ. To see what GNAT is
doing, use the -gnatdg switch, which shows the expanded source.





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1997-02-17  0:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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