comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Belmont <sbelmont700@gmail.com>
Subject: Unknown discriminants with nested records
Date: Thu, 16 Jun 2011 16:53:09 -0700 (PDT)
Date: 2011-06-16T16:53:09-07:00	[thread overview]
Message-ID: <1e197c14-a2ff-4867-85be-fda06a10e37b@a7g2000vby.googlegroups.com> (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



             reply	other threads:[~2011-06-16 23:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-16 23:53 Simon Belmont [this message]
2011-06-17  0:39 ` Unknown discriminants with nested records 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
replies disabled

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