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 06:48:13 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: How to Emulate C++ Macro with Static Local Variable? Date: 25 Sep 2003 09:43:31 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: <3F722C53.9020808@attbi.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1064497581 21795 128.183.235.92 (25 Sep 2003 13:46:21 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 25 Sep 2003 13:46:21 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: archiver1.google.com comp.lang.ada:42894 Date: 2003-09-25T13:46:21+00:00 List-Id: Hyman Rosen writes: > Robert I. Eachus wrote: > > This code is a bit ugly, but it does compile. And since Bar_Pointer > > is a constant, you can't accidently pass it to Test. There might be > > a cleaner cleverer way to do it, but this works. > > The cleanest option may be to run your code through a preprocessor > > and use a similar macro. > > Robert, I'm almost ashamed of you! You're abandoning your Ada ways > and starting to think like a C++ hacker! :-) AMEN! > The whole design is wrong in the C++ to begin with. If you want to > have a memoizing function, the job of caching old values belongs to > the function itself, not scattered in macros and variables all over > the place. Yes, that is probably the best way. Although it may be that the state should be preserved at a higher level; depends on the details. > In Ada, I suppose that I would just stick bar(foo:integer) into a > package, then have one of the Charles maps in the same package to > hold memoized values. The C code did not dynamically allocate memo state, but that is certainly a reasonable improvement. -- -- Stephe