From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: Ada Core Technologies announces GNATCOM
Date: 2000/04/12
Date: 2000-04-12T00:00:00+00:00 [thread overview]
Message-ID: <8d2d8j$1tk$1@nnrp1.deja.com> (raw)
In-Reply-To: d41J4.4674$q8.993149@news-east.usenetserver.com
In article <d41J4.4674$q8.993149@news-east.usenetserver.com>,
"David Botton" <David@Botton.com> wrote:
> Turbo C did that and many compilers still do.
>
> David Botton
Since I see David sharing the confusion, perhaps an example
is appropriate
int clobber (struct q m) {
m.a++;
return m.a;
}
called in c passing a value of the struct type does NOT change
the value of the passed variable.
But the RM requires (well its AI, but in practice we have
treated it as a requirement for the purposes of
interoperability) the corresponding Ada function
function clobber (m : q) return int;
to be interfaced by using call by reference, as a result of
which clobber will destroy the passed parameter.
But you can't unconditionally create a copy, since you may
want the reference semantics. Indeed the thought behind the
bad advice in the RM is that usually the C function will
look like
int clobber (struct q *m) ....
in which case the call by reference is appropriate.
The effect of C_Pass_By_Copy is to force the appropriate C
calling sequence for a pass by value, i.e. assuming that the
value is reasonably large, create a copy on the calling side,
and then pass a pointer to the copy.
I hope that makes this clear, I am surprised how many people
seem incredibly confused on this issue.
Part of the trouble historically is that C did not allow
structs to be passed by value till later on, so it is not
typical C style to use this feature.
This means that indeed the most common convention for passing
records in C is to pass them by pointer, but although this is
indeed the most common case, it was a goof in the RM to leave
Ada programs with no way of passing records by value.
Remember, call-by-address and passing-in-registers are
implementation techniques.
call-by-reference and call-by-value are high level semantic
concepts.
Don't get the two confused.
Sent via Deja.com http://www.deja.com/
Before you buy.
next prev parent reply other threads:[~2000-04-12 0:00 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-04-07 0:00 Ada Core Technologies announces GNATCOM Robert Dewar
2000-04-07 0:00 ` Vladimir Olensky
2000-04-08 0:00 ` Robert Dewar
2000-04-07 0:00 ` Ted Dennison
2000-04-08 0:00 ` Tom Hargraves
2000-04-08 0:00 ` David Starner
2000-04-08 0:00 ` Robert Dewar
2000-04-08 0:00 ` David
2000-04-08 0:00 ` tmoran
2000-04-08 0:00 ` David Botton
2000-04-08 0:00 ` Robert Dewar
2000-04-09 0:00 ` tmoran
2000-04-12 0:00 ` Robert Dewar
2000-04-12 0:00 ` C_Pass_By_Value, was " tmoran
2000-04-12 0:00 ` Tarjei T. Jensen
2000-04-12 0:00 ` David Botton
2000-04-12 0:00 ` Robert Dewar [this message]
2000-04-12 0:00 ` DuckE
2000-04-13 0:00 ` Robert Dewar
2000-04-12 0:00 ` David Botton
2000-04-12 0:00 ` Hyman Rosen
2000-04-12 0:00 ` David Botton
2000-04-13 0:00 ` Tarjei T. Jensen
2000-04-13 0:00 ` Robert Dewar
2000-04-14 0:00 ` Geoff Bull
2000-04-14 0:00 ` dale
2000-04-13 0:00 ` Robert Dewar
2000-04-12 0:00 ` Robert Dewar
2000-04-12 0:00 ` Robert A Duff
2000-04-13 0:00 ` Robert Dewar
2000-04-13 0:00 ` Robert A Duff
2000-04-15 0:00 ` Robert Dewar
2000-04-09 0:00 ` tmoran
2000-04-09 0:00 ` Robert Dewar
2000-04-09 0:00 ` Larry Kilgallen
2000-04-09 0:00 ` tmoran
2000-04-09 0:00 ` Robert Dewar
2000-04-09 0:00 ` Robert Dewar
2000-04-09 0:00 ` Marin D. Condic
2000-04-09 0:00 ` Brian Rogoff
2000-04-09 0:00 ` David Starner
2000-04-10 0:00 ` Gisle S�lensminde
2000-04-10 0:00 ` Hyman Rosen
2000-04-11 0:00 ` Gisle S�lensminde
2000-04-11 0:00 ` Hyman Rosen
2000-04-10 0:00 ` Marin D. Condic
2000-04-11 0:00 ` Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox