f



Warning: Storage error

   type My_String (Length: Integer := 0) is 
      record
         Str: String(1..Length);
      end record;
   
warning: creation of "My_String" object may raise Storage_Error

Why this warning?

-- 
Victor Porton - http://portonvictor.org
0
Victor
8/9/2014 3:20:57 PM
comp.lang.ada 8774 articles. 2 followers. Post Follow

6 Replies
371 Views

Similar Articles

[PageSpeed] 3

Using n normally defined integer with the bounds set to - 2GB .. 2GB, 
this type of unbound record size can range from 0 to 2GB.


All though today, most systems have 8 to 64 GB of main memory and up 
to 256 TB ( 2 ** 64 ) of virtual storage the Ada compiler does not 
know at compile time, the total run-time system memory or how much 
memory may be allocated to your program.  To correct this add a 
discriminant type or subtype

  --  Same size as just using "Integer' but compiler does not 
  --  generate the storage warnings 

  subtype D_Integer is Integer range 0 .. Integer ' Last ;

  type My_String ( Length : D_Integer := 0 ) is record
                                                     Str: String ( 1 .. Length ) ;
                                                   end record ;


You could say that GNAT is being overly touchy on some standard 
statements when using predefined types such as "Integer" or types 
that could cause a problem.


In <ls5e8r$373$1@speranza.aioe.org>, Victor Porton <porton@narod.ru> writes:
>   type My_String (Length: Integer := 0) is 
>      record
>         Str: String(1..Length);
>      end record;
>   
>warning: creation of "My_String" object may raise Storage_Error
>
>Why this warning?
>
>-- 
>Victor Porton - http://portonvictor.org

0
anon
8/9/2014 4:07:09 PM
On 08/09/2014 08:20 AM, Victor Porton wrote:
>     type My_String (Length: Integer := 0) is
>        record
>           Str: String(1..Length);
>        end record;
>
> warning: creation of "My_String" object may raise Storage_Error
>
> Why this warning?

There are 2 ways to implement such a type. One allocates just as much space as 
the current value (plus some small fixed overhead); the other allocates enough 
space for the largest value.

Some argue that Ichbiah intended the former, and there is at least one compiler 
that does it that way. It appears that you're using a compiler that uses the 
latter, and every such object will take at least Integer'Last bytes.

It also appears that you're attempting to reinvent Ada.Strings.Bounded.

-- 
Jeff Carter
"Insufficient laughter--that's grounds for divorce."
Play It Again, Sam
126
0
Jeffrey
8/9/2014 4:08:54 PM
On Sat, 09 Aug 2014 18:20:57 +0300, Victor Porton wrote:

>    type My_String (Length: Integer := 0) is 
>       record
>          Str: String(1..Length);
>       end record;
>    
> warning: creation of "My_String" object may raise Storage_Error
> 
> Why this warning?

Because you provided a default value.

It should have been:

   type My_String (Length: Natural) is record
      Str: String (1..Length);
   end record;

Or in the case of a varying length string with an upper bound:

   type My_String Size: Natural) is record
      Length : Natural := 0;
      Str: String (1..Size);
   end record;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
0
Dmitry
8/9/2014 4:21:01 PM
On Sat, 09 Aug 2014 09:08:54 -0700, Jeffrey Carter wrote:

> It also appears that you're attempting to reinvent Ada.Strings.Bounded.

A more frequent use case is a constant string allocated and initialized
once.

Ada.Strings.Bounded is practically unusable. Unbounded_String offers no
advantage over custom type because it requires explicit conversion to
String, and is suspicious for allocating more memory in advance than
actually required. RM is silent about the memory usage strategy.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
0
Dmitry
8/9/2014 4:26:23 PM
On 08/09/2014 09:26 AM, Dmitry A. Kazakov wrote:
>
> Ada.Strings.Bounded is practically unusable. Unbounded_String offers no
> advantage over custom type because it requires explicit conversion to
> String, and is suspicious for allocating more memory in advance than
> actually required. RM is silent about the memory usage strategy.

I agree that Ada.Strings.Bounded has a poor interface. I rarely use it. But when 
I do need bounded strings, I find the advantages of reuse usually outweight the 
disadvantages of the poor interface.

Using the standard library has the advantages of being more likely to be 
correct, requiring less development effort, and being easier for future readers 
to understand.

If you're worried about the implementation of an abstraction in the standard 
library in absence of any evidence that it is responsible for being unable to 
meet your requirements then you probably shouldn't be using Ada. Ada (and 
software engineering) is largely about abstraction and not worrying about 
implementations unless one has to.

-- 
Jeff Carter
"Insufficient laughter--that's grounds for divorce."
Play It Again, Sam
126
0
Jeffrey
8/9/2014 4:46:35 PM
On Sat, 09 Aug 2014 09:46:35 -0700, Jeffrey Carter wrote:

> Using the standard library has the advantages of being more likely to be 
> correct, requiring less development effort, and being easier for future readers 
> to understand.

Provided the library is used properly. Unbounded_String is not intended for
keeping constant strings. Or, considering another example of its frequent
*misuse*, for having String out-parameters.
 
> If you're worried about the implementation of an abstraction in the standard 
> library in absence of any evidence that it is responsible for being unable to 
> meet your requirements then you probably shouldn't be using Ada. Ada (and 
> software engineering) is largely about abstraction and not worrying about 
> implementations unless one has to.

I am worried about using wrong abstractions, which is poor engineering.
Unbounded_String is firstly poorly designed (should have been a type
related to String) and secondly is designed for a different purpose
(Strings of varying length).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
0
Dmitry
8/9/2014 4:57:27 PM
Reply:

Similar Artilces:

Error out instead of warn, i.e. warning('error', id)
In previous versions of Matlab (at least in R2007a), one could set the status of a warning message to be 'error'. This would cause any function encountering that particular warning to error out instead of just issuing a warning. The behavior was undocumented, and apparently has been removed from more recent versions of Matlab. I only recently discovered the error status possibility, but I found this little technique to be very helpful, both to permanently change certain warnings to errors (such as the inexact match error, 'MATLAB:dispatcher:InexactMatch', which used to d...

WARNING! WARNING! WARNING!
OK, I posted earlier about uninstalling the NWN2 beta patch because of game/system weirdness. This morning I started my machine and was greeted by a McAfee Personal Firewall tray error message of some kind, and had no internet access. After checking another machine on my network and determining my service wasn't down I decided the simplest thing to do was exercise XP's Restore Point capability. Since Wednesday I'd not only installed the NWN2 beta patch, but also the latest ATI Catalyst Suite and some sort of Java Runtime update I'd been bothered about, so my system ch...

can Ada give run-time error or warning for integer division with non-zero remainder?
In Ada when dividing 2 integers, the result is an integer with the remainder ignored. Hence 3/2 gives 1 ---------------------------------- with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; procedure foo4 is N : constant integer := 3; M : integer; begin M := N/2; put(M); end foo4; -------------------------- >gnatmake foo4.adb >./foo4 1 Now, suppose I want to know that a division between 2 integers has resulted in nonzero remainder that was thrown away. May be because my algorithm is meant to work only for even val...

commenting errors flagged as warnings instead of errors
I'm using Visual C++ on Windows Vista. Being "only human", I sometimes use ***************************************/ to underline a section of code instead of the correct /************************************/ I'm surprised by the fact that my mistake generates a warning rather than an error. How does the compiler understand *************************/ ? Thanks On Apr 8, 10:26=A0pm, Comp1...@yahoo.co.uk wrote: > I'm using Visual C++ on Windows Vista. > Being "only human", I sometimes use > ***************************************/ =A0 to ...

error and warning
Are warnings equally dangerous like errors ???? What is the difference between errors and warnings ?? asit wrote: > Are warnings equally dangerous like errors ???? Sometimes yes, sometimes even more dangerrous, sometimes less. Make sure you understand what the warning tries to tell you > What is the difference between errors and warnings ?? Usualla errors prevent the compiler to finish it's work, while with warning that (usually) doesn't happen Bye, Jojo In article <0f43d8bb-f186-4857-9fb3-32bcbe309bbc@f10g2000hsf.googlegroups.com>, asit <lipun4u@gmail.com>...

how do I capture errors/warnings from the error list via labview code
I can see the errors and warnings in the error list, but I can not grab the text and process it. I'm assuming that what you want to do is extract information from an error wire. Just wire an Unbundle By Name function to the wire, right click on the function and choose Select Item>Text. No. I want to retrieve the errors and warnings from the compiler. Example: You have written some code, but you have a broken arrow. You hit Ctrl+L and the error list appears. If you have the warnings box checked, you also see warnings like hidden objects etc... I want to capture the warnings from th...

Warning and error
HI all, I got the folowing errors and warning in an SPSS syntax(I am using SPSS 13): Warning. Command name: GET DATA >(2101) The column contained no recognized type; defaulting to >"Numeric[8,2]" >* Column 4 >Error # 1. Command name: DATASET >The first word in the line is not recognized as an SPSS command. >This command not executed. >Error # 1. Command name: DATASET >The first word in the line is not recognized as an SPSS command. >This command not executed. The SPSS syntax is as folows:*loading the excel file containing the...

why is this warning(error) ??????????
Guys I am using SAS 8.2 version on windows xp platform , I am trying to do something like this and I getting this warning in the Log can some body explain me why and how to solve it proc sql ; 36 create table test 37 (customer char(4) , 38 item char(10) , 39 units num, 40 unitcost num(8,2)); NOTE: Table WORK.TEST created, with 0 rows and 4 columns. 41 label customer = 'Customer number ' WARNING: This SAS global statement is not supported in PROC SQL. It has been ignored. 42 item = 'Item purchased ' 43 units = '# U...

When is an error not an error?
When it's OSS slopware, of course. http://www.angelfire.com/planet/dfs0/Knode_send_error.png On 2006-09-12 02:42, * DFS wrote: > When it's OSS slopware, of course. > > http://www.angelfire.com/planet/dfs0/Knode_send_error.png > Well, some time ago I had a problem with OE - too long reference line to other posts, and OE of course refused to send... then crashed. Should I name it a feature? -- Andrea On Tue, 12 Sep 2006 03:25:29 +0200, Andrea wrote: > On 2006-09-12 02:42, * DFS wrote: >> When it's OSS slopware, of course. >> >> http:/...

warnings as errors?
Is there a way to tell Ruby to treat warnings as errors? When writing my tutorial, I wanted a way to programmatically detect if a function was generating warnings, so I could show that warning on screen. Now I'm in another situation, using drb, where I can't see the warnings. (And I think they are causing these "broken pipe" errors I am getting, but even if they aren't...) I could handle all of these problems if I could tell Ruby to treat warnings as errors. Is there any way to do this? Thanks, Chris ...

When is an error not an error?
The Java language specification claims in: 8.8.7.1 Explicit Constructor Invocations .... "If an anonymous class instance creation expression appears within an explicit constructor invocation statement, then the anonymous class may not refer to any of the enclosing instances of the class whose constructor is being invoked." Helpfully it gives an example: "For example: class Top { int x; class Dummy { Dummy(Object o) {} } class Inside extends Dummy { Inside() { super(new Object() { int r = x; }); // err...

error and warning
I am not sure if this is directly related to C or the compiler (Xcode) I am using...but I will ask and see. I have started creating unique C files ( .c and .h) so that I can reuse some of the functions when doing the exercises in K&R. The code below is created in , for example, foo.c. Main.c contains the directive #included <stdio.h> yet unless I include the same directive in foo.h, the error and warning will not go away. My understanding, ( or rather misunderstanding ) was that once declared in main, one need not "redeclare" in foo.h. If this is unique to Xcode, I will a...

no error, no warning
Is will warning or error must be in this code? In my system no error. <?php class Insurance { function clsName() { echo get_class($this); } } Insurance::clsName(); ?> Andrew G. Koptyaev wrote: > Is will warning or error must be in this code? In my system no error. > > <?php > class Insurance > { > function clsName() > { > echo get_class($this); > } > } > Insurance::clsName(); > ?> > > > You need to instantiate an object of your class. $obj_Foo = new Insurance; $obj_Foo->clsName(); You might be trying to run before you can ...

WARNING or ERROR
Hi friends, I often use dataset options like KEEP, DROP, RENAME and WHERE. Sometimes I make a mistake and specify a non-existent variable. Sometimes I get a warning, sometimes I get an error: WARNING: The variable _Rater_ in the DROP, KEEP, or RENAME list has never been referenced. ERROR: The variable _Rater_ in the DROP, KEEP, or RENAME list has never been referenced. The warnings occur with the dataset options in the DATA statement. The errors occur with the dataset options in the SET statement. Non-existent variables in the MODIFY statement yields a warning, while they yield an error in M...

Web resources about - Warning: Storage error - comp.lang.ada

Resources last updated: 1/26/2016 3:26:23 PM