From: taashlo@sandia.gov
Subject: Re: How to Emulate C++ Macro with Static Local Variable?
Date: 29 Sep 2003 12:51:18 -0600
Date: 2003-09-29T12:51:18-06:00 [thread overview]
Message-ID: <u8yo7v36h.fsf@sandia.gov> (raw)
In-Reply-To: QB_db.9109$NX3.941@newsread3.news.pas.earthlink.net
Jeffrey Carter <spam@spam.com> 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
next prev parent reply other threads:[~2003-09-29 18:51 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-24 22:06 How to Emulate C++ Macro with Static Local Variable? taashlo
2003-09-24 23:44 ` Robert I. Eachus
2003-09-25 3:27 ` Hyman Rosen
2003-09-25 4:53 ` tmoran
2003-09-25 15:57 ` Robert I. Eachus
2003-09-25 19:09 ` tmoran
2003-09-29 14:57 ` taashlo
2003-09-29 18:12 ` Jeffrey Carter
2003-09-29 18:51 ` taashlo [this message]
2003-09-30 1:32 ` Jeffrey Carter
2003-09-30 1:54 ` tmoran
2003-09-30 13:02 ` taashlo
2003-09-30 20:25 ` Jeffrey Carter
2003-09-30 2:45 ` Robert I. Eachus
2003-09-30 3:24 ` tmoran
2003-09-25 13:43 ` Stephen Leake
2003-09-25 12:59 ` Tad Ashlock
2003-09-25 16:11 ` Robert I. Eachus
2003-09-25 18:13 ` Randy Brukardt
2003-09-25 23:40 ` Robert I. Eachus
2003-09-25 11:54 ` Gautier
2003-09-25 16:14 ` Robert I. Eachus
2003-09-25 18:06 ` Tad Ashlock
2003-09-28 8:42 ` Gautier Write-only
2003-09-28 20:06 ` Jeffrey Carter
2003-09-29 2:13 ` Gautier Write-only
2003-09-25 13:41 ` Stephen Leake
2003-09-25 17:23 ` Tad Ashlock
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox