comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: How to Emulate C++ Macro with Static Local Variable?
Date: Tue, 30 Sep 2003 02:45:29 GMT
Date: 2003-09-30T02:45:29+00:00	[thread overview]
Message-ID: <3F78EE34.9090902@comcast.net> (raw)
In-Reply-To: uhe2vvdzk.fsf@sandia.gov

taashlo@sandia.gov wrote:

> Although I originally thought that the C++ implementation was a bit of a
> hack, I'm beginning to think that this is a somewhat elegant solution to
> a problem that can't be elegantly solved in Ada.  By elegant, in this
> case, I mean simple, extensible, and maintainable.

Remember that the code I posted was more of an existance proof rather 
than an elegant implementation of what you were asking for.  I could 
probably come up with a version that hid away most of the details from a 
user, but I wanted it to be possible to see what was going on.

Having said that, the general Ada solution to this type of problem is 
generics.  Generics allow you to have two points at which variables are 
bound to parameters, which allows for a much greater richness of 
application than the C++ code.  The flip side of that is that the C++ 
code is simpler.  In Ada you can have one memo per call site, in C++ you 
must.  Which is better?  What do you want to do?  The Ada approach is 
more general, but the cost is writing a bit more per call.

As for the (very gory as submitted) version I posted, I think that a 
return address attribute if available would be much better.  You are 
free to add it to GNAT, or more to the point write a Return_Address 
function and just use that.  Of course, such a function would not be 
portable, which is why I think that an attribute, possibly in Annex C 
would be a the best approach.  In fact, if someone wants to propose an 
Ada.Call_Stack package for Ada 0Y, I'd vote for it.  However, I am much 
more likely to try writing the package (for at least one GNAT version) 
first, and I suspect that the ARG as a whole would not vote for it this 
time around. (It is very late in the game.)

-- 
                                                     Robert I. Eachus

"Quality is the Buddha. Quality is scientific reality. Quality is the 
goal of Art. It remains to work these concepts into a practical, 
down-to-earth context, and for this there is nothing more practical or 
down-to-earth than what I have been talking about all along...the repair 
of an old motorcycle."  -- from Zen and the Art of Motorcycle 
Maintenance by Robert Pirsig




  parent reply	other threads:[~2003-09-30  2:45 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 [this message]
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