From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e3c7ee8cd1d3f414 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: rep clause in generics Date: 1997/03/14 Message-ID: <3329512E.4900@gsfc.nasa.gov>#1/1 X-Deja-AN: 225453294 References: <01bc3057$61a78db0$81946482@vkpc131> Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Reply-To: Stephen.Leake@gsfc.nasa.gov Newsgroups: comp.lang.ada Date: 1997-03-14T00:00:00+00:00 List-Id: 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