From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,984d3d7860d7c8c X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Where are returned values stored? Date: Sat, 29 May 2004 09:03:10 +0200 Organization: AdaCL Message-ID: <60328483.MtZnWf8h2m@linux1.krischik.com> References: <75s9b0pgo91ctvlm5op2rcql82t9ip4me2@4ax.com> <1dptc.49822$tb4.1731604@news20.bellglobal.com> <2lNtc.56154$tb4.2140194@news20.bellglobal.com> Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1085814485 06 19055 VuuzGPUvB4nHp2d 040529 07:08:05 X-Complaints-To: usenet-abuse@t-online.de X-ID: JOH01iZdgeEy6SQBoDw+KMV5PONrlLLBfV46x+EcDCJx3ND0f4vDwi User-Agent: KNode/0.7.7 Xref: controlnews3.google.com comp.lang.ada:903 Date: 2004-05-29T09:03:10+02:00 List-Id: 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