comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: How to Emulate C++ Macro with Static Local Variable?
Date: Thu, 25 Sep 2003 16:11:45 GMT
Date: 2003-09-25T16:11:45+00:00	[thread overview]
Message-ID: <3F7313BD.2050602@attbi.com> (raw)
In-Reply-To: 5917f4d0.0309250459.59940bc9@posting.google.com

Tad Ashlock wrote:

> I've been trying ideas along these lines for a few days, but I haven't
> been able to make them work.  I understand how the procedure would get
> created, but I don't understand where the data is uniquely cached for
> each procedure call. (The C++ implementation above does it in t_->data.)

>>   type Subprogram_Record is record
>>     SP: Subprogram_Pointer;
-- Put whatever else you want right here. Just like in the C++ there has 
  -- to be a local modifiable object of this type to make the call.
>>   end record;

> I'm not following this one at all.  Where is the cached data?

As I said, it goes in the record with the access value.  The caller has 
to declare a local copy to make a call, and that stores the data.  I 
much prefer the more Ada-like abstraction where the user instantiates a 
generic, and the generic has both local data and a (local) instance of 
the subroutine.

> Thank you so much, Robert, for taking the time to reply to my question.

It is an interesting question, and as a result I may actually advocate a 
language change.  If we had the equivalent of access discriminants for 
Ada subprograms, this would be much cleaner.  I think that the right 
level of implementation is an attribute.  So that 
Some_Subprogram'Called_From gets you the called from address.  It is not 
the best solution for this problem, but there may be a way to define it 
to be useful in doing stack tracebacks. (Which argues for the system 
programming annex.)

-- 
                                         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.




  reply	other threads:[~2003-09-25 16:11 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
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 [this message]
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