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-29 11:52:31 PST Path: 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: Re: How to Emulate C++ Macro with Static Local Variable? Date: 29 Sep 2003 12:51:18 -0600 Organization: Sandia National Laboratories, Albuquerque, NM USA Sender: taashlo@SADL10553 Message-ID: References: <3F73107A.1060502@attbi.com> <04Hcb.577973$Ho3.106182@sccrnsc03> NNTP-Posting-Host: sadl10553.sandia.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sass2141.sandia.gov 1064861473 11588 134.253.225.126 (29 Sep 2003 18:51:13 GMT) X-Complaints-To: usenet@sass2141.sandia.gov NNTP-Posting-Date: Mon, 29 Sep 2003 18:51:13 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: news1.google.com comp.lang.ada:196 Date: 2003-09-29T12:51:18-06:00 List-Id: Jeffrey Carter writes: > taashlo@sandia.gov wrote: > > tmoran@acm.org writes: > > > >> void log(int *t){if(*t++ > 100)raise_the_exception;} > >> #define LOG if (1) { \ > >> static int t_; \ > >> log(&t_);\ > >> } else ((void)0) > > Are ints in C++ automatically initialized to zero? I admit my C++ is > not very good, but this looks as if it could raise the exception after > fewer than 100 invokations, or after 101 invocations. (I assume this > is C++ and not C because I don't recall C having exceptions.) Yes, static ints will be initialized to zero. > > There's only two options that I can think of: > > 1) Use a unique ID for each call. But this turns into a maintenance > > nightmare when you get a few hundred calls or more. > > 2) Use the return address of the call. But there was a short > > discussion > > about how Ada doesn't currently have a way of accessing the return > > address of a subprogram. > > 3. Use a unique instantiation of a generic package for each call. The > instantiations of the package must be at a nesting level that ensures > that they will exist for the entire lifetime of the executable region > in which they are used. Won't a unique instantiation require a unique name? This is the same problem with item 1) above. A single unique instantiation is no problem, but try a thousand instantiations whose associated function calls are scattered across fifty files. Where using the wrong instantiation can lead to subtle and difficult-to-reproduce errors. This is not a solution that I'd voluntarily aim for. > -- > Jeff Carter > "You tiny-brained wipers of other people's bottoms!" > Monty Python & the Holy Grail > 18