comp.lang.ada
 help / color / mirror / Atom feed
* Discriminated types with default discriminants
@ 2005-11-03 15:50 Maciej Sobczak
  2005-11-03 16:06 ` Martin Krischik
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Maciej Sobczak @ 2005-11-03 15:50 UTC (permalink / raw)


Hi,

Consider this:

procedure Hello is

    type Discriminated(Size : Integer := 10) is
       record
          Value : String (1..Size);
       end record;

    S : Discriminated;

begin
    null;
end Hello;


Compiler (GNAT) gives me two warnings:

      5.          Value : String (1..Size);
                                     |
         >>> warning: creation of object of this type may raise 
Storage_Error

      8.    S : Discriminated;
            |
         >>> warning: Storage_Error will be raised at run-time


Moreover, it keeps a promise and indeed the program raises STORAGE_ERROR 
at run-time.

What's happening here? Why the object S is not created with 10 as the 
default discriminant?

I can get rid of the second warning by declaring S as:

S : Discriminated(10);

Indeed - program runs fine (i.e. it does not raise any exception). 
What's the difference?


I can get rid of the first warning with this:

    subtype MyInt is Integer;
    type Discriminated(Size : MyInt := 10) is
    -- ...

What's the difference?


-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



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

end of thread, other threads:[~2005-12-02 18:22 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-03 15:50 Discriminated types with default discriminants Maciej Sobczak
2005-11-03 16:06 ` Martin Krischik
2005-11-03 23:10   ` Robert A Duff
2005-11-04  5:01     ` Jeffrey R. Carter
2005-11-03 16:21 ` Ed Falis
2005-11-03 17:28 ` Dmitry A. Kazakov
2005-11-03 18:51 ` Jeffrey R. Carter
2005-11-03 23:08   ` Robert A Duff
2005-11-04  0:08     ` Adam Beneschan
2005-11-29  2:49       ` Randy Brukardt
2005-12-02 18:22         ` Robert A Duff
2005-11-04  9:18   ` Maciej Sobczak
2005-11-04  3:27 ` Brian May
2005-11-04 13:09   ` Stephen Leake
2005-11-04 17:58   ` Martin Krischik

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