comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Generic Zero Length Array
Date: Fri, 22 Feb 2008 08:52:39 -0800 (PST)
Date: 2008-02-22T08:52:39-08:00	[thread overview]
Message-ID: <4c024f41-3ff8-4d70-ac6c-551f129289a1@d21g2000prf.googlegroups.com> (raw)
In-Reply-To: Pine.LNX.4.64.0802221510150.9614@th.informatik.uni-mannheim.de

On Feb 22, 6:23 am, Stefan Lucks <lu...@th.informatik.uni-mannheim.de>
wrote:
> On Fri, 22 Feb 2008, shaunpatter...@gmail.com wrote:
> > How do I initialize this array when I can't know what type it is or
> > will be?
> > if Error_Condition then
> >  declare
> >    type Result is new Element_List (Indexing.First + 1 ..
> > Indexing'First);
> >    Result_String : Result;
>
>      Result_String : Result := (others => Some_Default_Value);
>
> >  begin
> >     return Element_List (Result);
> >  end;
> > end if;
>
> This should work. The default value doesn't matter at all, because the
> array is empty. But you still need to know a default value of the
> appropriate type.

If the *only* use of this default value would be to use it as an
initializer for an array that we know is going to be empty, so that
the default value is never used, I don't think I'd recommend this
solution.  It may work to get rid of the warnings, but it seems like a
poor design idea to require a parameter that is never used.

I think one of Bob's solutions is preferable, if it's really necessary
to get rid of the warnings.  This is simply a case where you know more
than the compiler.

However, in a case where you do need to initialize something of a
generic formal type, adding an "initial value" generic parameter is
the way to do it.

                                    -- Adam



  reply	other threads:[~2008-02-22 16:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-22 13:31 Generic Zero Length Array shaunpatterson
2008-02-22 13:53 ` Egil Høvik
2008-02-22 13:55   ` shaunpatterson
2008-02-22 14:11     ` Georg Bauhaus
2008-02-22 19:25   ` Randy Brukardt
2008-02-22 23:01     ` Adam Beneschan
2008-02-23  9:30       ` Dmitry A. Kazakov
2008-02-23 14:27       ` Robert A Duff
2008-02-23 16:16         ` Dmitry A. Kazakov
2008-02-25 16:41         ` Adam Beneschan
2008-02-25 19:14           ` Robert A Duff
2008-02-22 19:25   ` Randy Brukardt
2008-02-22 19:25   ` Randy Brukardt
2008-02-22 14:23 ` Stefan Lucks
2008-02-22 16:52   ` Adam Beneschan [this message]
2008-02-22 14:26 ` Robert A Duff
2008-02-22 15:22 ` Stefan Bellon
2008-02-22 23:03   ` Adam Beneschan
2008-02-23 10:19     ` Stefan Bellon
replies disabled

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