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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e26ffba340697f29 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-18 13:09:42 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.cwix.com!newsfeed.nyc.globix.net!uunet!ash.uu.net!world!bobduff From: Robert A Duff Subject: Re: Type Conversion in an Assignment Statement Sender: bobduff@world.std.com (Robert A Duff) Message-ID: Date: Mon, 18 Jun 2001 20:08:26 GMT References: <3B2DB8B9.1A26F90F@informatik.uni-jena.de> Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.3/Emacs 19.34 Xref: archiver1.google.com comp.lang.ada:8870 Date: 2001-06-18T20:08:26+00:00 List-Id: Carsten Freining writes: > type IntegerAccessType is access Integer; > subtype IntegerSubType is Integer range 1..100; > Pointer: IntegerAccessType := new IntegerSubType; > begin > Pointer.all :=105; > end; > This is a correct program. I thought it would raise a constraint_error, No, it will not raise C_E. The designated subtype of IntegerAccessType is Integer. When you allocate with "new IntegerSubType", it does *not* remember the bounds of IntegerSubType. In the assignment "Pointer.all := 105;", it's checking that 105 is within the bounds of Integer, not within the bounds of IntegerSubType. This is how elementary types work. Composite types work differently: if you allocate an array or record on the heap, it *does* remember the bounds or discriminants of what you allocated, and it will check that they don't change, and raise C_E if you try. Anyway, it's probably better to write "new Integer" above, to avoid this confusion. I'm too lazy to quote chapter and verse here. If you really want to understand the RM wording, remember that the name in a type_declaration is the name of a subtype (the "first subtype"). A type_declaration also creates a type, but types in Ada do not have names. Integer and IntegerSubType are both subtypes (of the same underlying type). This terminology is admittedly a bit confusing, so most people are happy to say "the type Integer", when strictly speaking they really mean "the type of subtype Integer". - Bob P.S. You ought to use the generally accepted Ada style, and call it Integer_Access_Type, rather than IntegerAccessType.