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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c32f54b2230c68d7 X-Google-Attributes: gid103376,public From: Tucker Taft Subject: Re: Ada version of C's 'static' Date: 1999/07/23 Message-ID: <3798EDE9.90B9623B@averstar.com>#1/1 X-Deja-AN: 504565111 Content-Transfer-Encoding: 7bit Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <7n03us$862$1@nnrp1.deja.com> Content-Type: text/plain; charset=us-ascii Organization: AverStar (formerly Intermetrics) Burlington, MA USA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-07-23T00:00:00+00:00 List-Id: Craig Allen wrote: > > I've written some code in a procedure that operates on a table of > constants. The table is used only by that procedure. Right now, I have > that table defined locally to that procedure. I believe the table is > regenerated every time the procedure is called. Why do you believe it is regenerated? It shouldn't be if the table is of compile-time known size with compile-time known values. > In C, I'd declare this table static in that function. This would give > me static duration and block scope for that function. > > I don't want to define this table at 'package scope', as only 1 > procedure uses this table (and the values would be removed from the > code that uses them). I would prefer not to build the table at > elaboration time, because I'd like the definition to be close to the > code that's using it, not at the bottom of the package. > > In short, this is exactly what I want, except in Ada. > > void foo(void) > { > static const int bar[] = {1, 2, 3, 4, 5}; > ... > } > > Or is there a 'more Ada' way of doing this? If the values are known at compile-time, then any Ada compiler worth its salt will allocate and initialize the table statically, no matter where it is declared. If the compiler is not worth its salt, then you probably have bigger problems anyway, so I wouldn't worry about that contingency. Either that, or complain to/threaten your compiler vendor ;-). If the values are *not* known at compile-time, then C wouldn't allow it to be static anyway (though C++ would, and boy is the initialization "funky" in that case). > Thanks for any help. > -Craig > > Sent via Deja.com http://www.deja.com/ > Share what you know. Learn what you don't. -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA