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 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-25 12:09:49 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!newsfeed2.easynews.com!newsfeed1.easynews.com!easynews.com!easynews!crtntx1-snh1.gtei.net!news.gtei.net!chcgil2-snh1.gtei.net!news.bbnplanet.com!wn11feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc03.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: How to Emulate C++ Macro with Static Local Variable? References: <3F73107A.1060502@attbi.com> X-Newsreader: Tom's custom newsreader Message-ID: <04Hcb.577973$Ho3.106182@sccrnsc03> NNTP-Posting-Host: 12.234.124.41 X-Complaints-To: abuse@comcast.net X-Trace: sccrnsc03 1064516988 12.234.124.41 (Thu, 25 Sep 2003 19:09:48 GMT) NNTP-Posting-Date: Thu, 25 Sep 2003 19:09:48 GMT Organization: Comcast Online Date: Thu, 25 Sep 2003 19:09:48 GMT Xref: archiver1.google.com comp.lang.ada:42920 Date: 2003-09-25T19:09:48+00:00 List-Id: I remain confused. I thought the OP wanted something that used storage that invisibly depended on the static *location* of a call, and that's why he used separate "static" variables. > > cache information for each unique call to bar() such that subsequent > > calls from that location can be processed *much* faster. ^^^^^^^^^^^^^^^^^^ I gather that's not the correct interpretation. If he is willing to manually specify the particular cache by BAR(10); -- cache number 10 or package P10 is new P(10); -- cache number 10 package P20 is new P(20); -- cache number 20 package P30 is new P(30); -- cache number 30 or Local_Pointer.SP.all(3, Local_Pointer); -- cache number 3 then why not just: type s is record ... t : array(1 .. 100) of s; -- array of caches ... for i in 0 .. 54 loop case wozit is when 1 => bar(cache_to_use=>t( 3)); when 2 => bar(cache_to_use=>t(20)); when 3 => bar(cache_to_use=>t(14)); end case; end loop; To somewhat change the example, suppose we want to keep track of how often different sections of code are run. The usual method is to do something like type sections is (initialization, processing_input, ... and sprinkle around statements like log(initialization); ... log(process input); Suppose that for some reason we don't just want to set a boolean, or a counter for each section, but we want to raise an exception if any section is run more than 100 times (maybe we're worried its RAM area will die of overuse or something ;) Then in C we could void log(int *t){if(*t++ > 100)raise_the_exception;} #define LOG if (1) { \ static int t_; \ log(&t_);\ } else ((void)0) and then we could sprinkle the statement LOG; around in the program. How could one implement a similar thing in Ada, where the "log" call does not need a parameter, but implicitly has one by virtue of its static location in the code?