comp.lang.ada
 help / color / mirror / Atom feed
* Unknown discriminants with nested records
@ 2011-06-16 23:53 Simon Belmont
  2011-06-17  0:39 ` Adam Beneschan
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Belmont @ 2011-06-16 23:53 UTC (permalink / raw)


New to ada (2005), and trying to figure out how to create records of
other records with unknown discriminants, e.g. like this:

package Test_Package is

    type Foo_Type (<>) is limited private;  -- some record with
unknown discriminants.

    t1: Foo_Type := MakeAFooType; -- works fine being built by a
function

    type BarType is
    record
     B1: Integer;
     -- other record elements
     B2: FooType := MakeAFooType;  -- Error, unconstrained subtype.
    end record;

private

    type FooType is limited
    record
     F1: Integer;
    end record;

end Test_Package;


The (<>) seems to be the defacto way to limit creation to a function,
yet it seemingly precludes you from using it in a nested record.  It
seems strange that there is the ability to declare a standalone object
of that type, but trying to nest one within another record throws an
"unconstrained subtype" error; if it knows the constraints one place,
why doesn't it know them several lines down?  I have tried all the
various syntaxes I can find, but nothing seems to work (though it
wouldn't be the first time there was some esoteric syntax that escaped
me).  So, that being said:

1. What is the appropriate syntax to do this?
2. If not, what is the technical reason and design decision why?
3. Are there workarounds?
4. Am I programming Ada the wrong way? (this happens often)
4. Can anyone point me to the section in the LRM that specifies this
either way?


Thanks



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

end of thread, other threads:[~2011-06-20 16:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-16 23:53 Unknown discriminants with nested records Simon Belmont
2011-06-17  0:39 ` Adam Beneschan
2011-06-17  1:48   ` Simon Belmont
2011-06-17 14:50     ` Robert A Duff
2011-06-18  8:33       ` Yannick Duchêne (Hibou57)
2011-06-20 16:16         ` Adam Beneschan
2011-06-17  6:03   ` Jeffrey Carter

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