comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: rep clause in generics
Date: 1997/03/14
Date: 1997-03-14T00:00:00+00:00	[thread overview]
Message-ID: <3329512E.4900@gsfc.nasa.gov> (raw)
In-Reply-To: 01bc3057$61a78db0$81946482@vkpc131


Jonas Nygren wrote:
> 
> I tried to write a small generic package that represents packed arrays of
> some element type:
> 
> generic
>    type Element_Type is private;
> package Gen_Buffers is
>    type Index_Type  is new Natural;
>    type Buffer_Type is array(Index_Type range <>) of Element_Type;
> 
>    pragma Pack (Buffer_Type);
>    for Buffer_Type'Component_Size use Element_Type'Size; -- line 9
> end Gen_Buffers;
> 
> The compiler complained with:
> 
>    gen_buffers.ads:9:39: static integer expression required here
> 
> I thought that Element_Type'Size was a static integer expression. Am I or
> the compiler in error?

Sorry, but you are. Consider:

procedure Non_Static_Instantiation (Length : in Integer)
is
	type String_Index is 1 .. Length;
	subtype Fixed_String is String (String_Index);

	package Fixed_String_Buffers is new Gen_Buffers (Fixed_String);
begin
	...
end;

Element_Type'size is determined by a run-time parameter, so it is NOT
static.

	
> 
> /jonas

-- 
- Stephe




  parent reply	other threads:[~1997-03-14  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-03-14  0:00 rep clause in generics Jonas Nygren
1997-03-14  0:00 ` Robert Dewar
1997-03-20  0:00   ` Nick Roberts
1997-03-14  0:00 ` Robert A Duff
1997-03-15  0:00   ` Robert Dewar
1997-03-14  0:00 ` Stephen Leake [this message]
1997-03-15  0:00   ` Robert Dewar
1997-03-20  0:00   ` Aaro Koskinen
replies disabled

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