comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Variant record limitation - what's a better solution?
Date: Wed, 03 Jul 2013 09:23:09 -0700
Date: 2013-07-03T09:23:09-07:00	[thread overview]
Message-ID: <kr1ir1$asc$1@dont-email.me> (raw)
In-Reply-To: <0606a658-9816-4611-84dd-4f999bf6018e@googlegroups.com>

On 07/03/2013 12:52 AM, Peter Brooks wrote:
>
> type
> my_object(X : size_type) is
>         record
>                name : string(1..80);
>                case X is
>                   when small => Y : small_type; -- line 20
>                   when medium => Y : medium_type; -- line 21
>                   when large => Y: large_type; -- line 22
>                end case;
>         end record;
>
> The errors are:
> line 21  'Y' conflicts with declaration at line 20
> line 22 'Y' conflicts with declaration at line 21
>
> I was hoping to have a different type depending on the case, but this doesn't seem allowed. What would achieve this?

The problem isn't the types but the component identifiers. Each component name 
must be unique, even across different variants. So you could do something like

type My_Object (Size : Size_ID) is record
    Name : String (1 .. 80);

    case Size is
    when Small =>
       Y_Small : Small_Value;
    when Medium =>
       Y_Medium : Medium_Value;
    when Large =>
       Y_Large : Large_Value;
    end case;
end record;

-- 
Jeff Carter
"My brain hurts!"
Monty Python's Flying Circus
21


  parent reply	other threads:[~2013-07-03 16:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-03  7:52 Variant record limitation - what's a better solution? Peter Brooks
2013-07-03  8:11 ` Georg Bauhaus
2013-07-03  9:39   ` Peter Brooks
2013-07-03 16:23 ` Jeffrey Carter [this message]
2013-07-03 18:35 ` Shark8
2013-07-03 19:26 ` Adam Beneschan
2013-07-09 11:48   ` Peter Brooks
2013-07-09 15:11     ` Adam Beneschan
2013-07-10  1:11       ` Peter Brooks
2013-07-03 20:55 ` Per Sandberg
2013-07-09  6:38 ` Peter Brooks
2013-07-09  7:49   ` Simon Wright
2013-07-09  8:22   ` Georg Bauhaus
2013-07-09 14:12   ` Eryndlia Mavourneen
replies disabled

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