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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,196864e6c216ca4f,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-24 15:12:19 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!news-in-sterling.newsfeed.com!feeder.nmix.net!feeder.swcp.com!news.sandia.gov!not-for-mail From: taashlo@sandia.gov Newsgroups: comp.lang.ada Subject: How to Emulate C++ Macro with Static Local Variable? Date: 24 Sep 2003 16:06:41 -0600 Organization: Sandia National Laboratories, Albuquerque, NM USA Sender: taashlo@SADL10553 Message-ID: NNTP-Posting-Host: sadl10553.sandia.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sass2141.sandia.gov 1064441197 28660 134.253.225.126 (24 Sep 2003 22:06:37 GMT) X-Complaints-To: usenet@sass2141.sandia.gov NNTP-Posting-Date: Wed, 24 Sep 2003 22:06:37 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: archiver1.google.com comp.lang.ada:42866 Date: 2003-09-24T16:06:41-06:00 List-Id: Hello, I'm trying to port a small C++ library to Ada95. Most of it is going quite well in that the Ada implementation is smaller, simpler, and easier to follow than the C++ implementation. But I've ran into a hurdle with the following C++ construction: class Test { ... protected: struct s { int data[8]; }; ... void bar(s *t, int foo); #define BAR(foo_) if (1) { \ static s t_; \ bar(&t_, foo_);\ } else ((void)0) ... }; What happens is that when you do this: BAR(10); it expands to this: if (1) { static s t_; bar(&t_, 10); } else ((void)0); This, in effect, creates a (hidden) static local variable for each call to bar(). This static variable (actually a structure, t_) is used to cache information for each unique call to bar() such that subsequent calls from that location can be processed *much* faster. For instance, the following code would create three of the hidden local variables: for (int i = 0; i < 55; ++i) { switch (wozit()) { case 1: BAR(10); break; case 2: BAR(20); break; case 3: BAR(30); break; } } The first time each BAR() is encountered, it does the full processing, but subsequent calls to the *same* BAR() used it's unique cached information and go much faster. Any ideas on how I can achieve this with Ada95? Thank you, Tad