From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: How to Emulate C++ Macro with Static Local Variable?
Date: Thu, 25 Sep 2003 15:57:50 GMT
Date: 2003-09-25T15:57:50+00:00 [thread overview]
Message-ID: <3F73107A.1060502@attbi.com> (raw)
In-Reply-To: Owucb.146738$mp.74846@rwcrnsc51.ops.asp.att.net
tmoran@acm.org wrote:
> I don't see how
> one might do that without a preprocessor, and I don't see how one could
> (portably) get hold of the Instruction Counter for storage and later
> comparison, in Ada code.
I showed how. You set it up so that the memoizing function is not
visible. All that is visible is a constant record containing a
subprogram access value. To make a call you have to make a (variable)
copy of the constant, and pass that on the call. Inside the subprogram
this is a new call site. Create a new access value, reset the
(record) parameter to the new value, do the initial call processing,
then call the (hidden) value which will be returned.
This second value of the parameter calls the routine which does the
actual processing sans the initial call code. This way there is no
lookup or anything to be done in either case. Call the initial value in
the constant, this is the first call from this site. Call the returned
value, and this is a subsequent call. If you want you can either make
sure that the record containing the access value is passed by reference,
or add an access discriminant so that inside the first subprogram you
can cache a list of call sites if you want to.
--
Robert I. Eachus
Ryan gunned down the last of his third white wine and told himself it
would all be over in a few minutes. One thing he'd learned from
Operation Beatrix: This field work wasn't for him. --from Red Rabbit by
Tom Clancy.
next prev parent reply other threads:[~2003-09-25 15:57 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 [this message]
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
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