comp.lang.ada
 help / color / mirror / Atom feed
From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: Where are returned values stored?
Date: Sat, 29 May 2004 09:03:10 +0200
Date: 2004-05-29T09:03:10+02:00	[thread overview]
Message-ID: <60328483.MtZnWf8h2m@linux1.krischik.com> (raw)
In-Reply-To: 2lNtc.56154$tb4.2140194@news20.bellglobal.com

Warren W. Gay VE3WWG wrote:

>  > Interesting to consider this with a recursive procedure, but yes, it
>  > should work.
>  >
>  > JAF
> 
> Calling Conventions:
> 
> If this indeed happens (on a given platform), I would think
> that the calling convention used is +critical+. For example,
> if you forced an Ada routine to use the C calling convention,
> I would bet that on most platforms, that all return values
> must be _copied_ or placed on the heap (temporarily). At least
> this would be true for strings/arrays etc. where the size
> was not known in advance.

The "C" calling convention places the return value inside a hidden static
variable. A pointer to this variable is then returned.

So you correctly observed: size need to be known at compile time. Also: this
is not multi tasking capable.

> This is because most platforms (I think), have C
> programs pop off their stack frame as part of the
> return "process" (I believe this to be true of
> Wintel and Linux on Intel for example).

On Windows the most used calling convention is not "C" bot "DLL" or "API".
With calling convention "DLL" the caller reserves space for the return
variable on the stack and passes a pointer to that space.

Again: not good for indefinite types.

> So the compiler might be forced to copy the return
> value to some other location, or make some other
> arrangement for non Ada calling conventions. You
> obviously can't just re-extend the stack frame after
> a return because of the possibility of UNIX process
> signal calls or interrupt processing that
> may overwrite the stack area of interest.

GNAT will warn you if you pass indefinite types with either "C" or "DLL"
calling convention.

> Just keep in mind that my responses on this thread
> are all conceptual/conjecture, and has no documented
> factual basis in any existing implementation ;-)

My are practical experience on Linux/Windows with GNAT. It might be
different for other Platforms.

If you need to return complex types between Ada and C I would suggest
calling convention "DLL". GNAT Linux understands calling convention "DLL"
as well and will do the right thing.

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




  reply	other threads:[~2004-05-29  7:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-26 19:46 Where are returned values stored? (follow up to yesterday's question) James Alan Farrell
2004-05-26 20:44 ` Simon Wright
2004-05-27  7:51   ` Dmitry A. Kazakov
2004-05-27  9:39 ` Where are returned values stored? Marius Amado Alves
2004-05-27 17:05   ` Warren W. Gay VE3WWG
2004-05-27 20:24     ` James Alan Farrell
2004-05-28 20:33       ` Warren W. Gay VE3WWG
2004-05-29  7:03         ` Martin Krischik [this message]
2004-05-29 13:19           ` Larry Kilgallen
2004-05-30  7:10             ` Martin Krischik
2004-06-02  3:14         ` Robert I. Eachus
2004-05-30 21:17     ` Nick Roberts
2004-05-31 12:58       ` Warren W. Gay VE3WWG
2004-06-02  4:07         ` Robert I. Eachus
2004-06-02 12:42           ` Warren W. Gay VE3WWG
2004-06-03  2:00             ` Nick Roberts
2004-06-03  4:34             ` Robert I. Eachus
2004-06-03 16:06               ` Warren W. Gay VE3WWG
2004-06-03 16:13               ` Nick Roberts
2004-06-07  1:53                 ` Robert I. Eachus
2004-06-07 13:09                   ` Larry Kilgallen
2004-06-09  7:03                     ` Robert I. Eachus
2004-06-05 17:13             ` Simon Wright
2004-05-27 17:11   ` Martin Krischik
2004-05-27 17:07 ` Where are returned values stored? (follow up to yesterday's question) Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox