comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@averstar.com>
Subject: Re: Ada version of C's 'static'
Date: 1999/07/23
Date: 1999-07-23T00:00:00+00:00	[thread overview]
Message-ID: <3798EDE9.90B9623B@averstar.com> (raw)
In-Reply-To: 7n03us$862$1@nnrp1.deja.com

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




  parent reply	other threads:[~1999-07-23  0:00 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-19  0:00 Ada version of C's 'static' Craig Allen
1999-07-19  0:00 ` David Botton
1999-07-20  0:00 ` Simon Wright
1999-07-23  0:00 ` Tucker Taft [this message]
1999-07-30  0:00   ` Craig Allen
1999-08-03  0:00     ` Compilers for VAX Was: " Erdelyi Gaspar
1999-08-03  0:00       ` Larry Kilgallen
1999-08-04  0:00       ` Steve Doiel
1999-08-05  0:00         ` Robert Dewar
1999-08-05  0:00           ` Larry Kilgallen
1999-08-06  0:00             ` Robert A Duff
1999-08-06  0:00               ` Larry Kilgallen
1999-08-09  0:00                 ` Robert A Duff
1999-08-09  0:00                   ` Richard D Riehle
1999-08-09  0:00                     ` Tucker Taft
1999-08-10  0:00                     ` Robert A Duff
1999-08-08  0:00               ` Robert Dewar
1999-08-04  0:00       ` Robert Dewar
1999-08-04  0:00         ` Rod Chapman
1999-08-04  0:00           ` Robert Dewar
1999-08-04  0:00           ` Larry Kilgallen
1999-08-04  0:00             ` Robert Dewar
1999-08-04  0:00             ` Marin David Condic
1999-08-04  0:00               ` Larry Kilgallen
1999-08-04  0:00               ` Robert Dewar
1999-08-04  0:00         ` Chris Miller
1999-08-05  0:00           ` Robert Dewar
replies disabled

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