www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/16/13:53:22

Mime-Version: 1.0
To: "Paul Derbyshire" <pderbysh AT usa DOT net>, djgpp AT delorie DOT com
From: Nate Eldredge <nate AT cartsys DOT com>
Subject: Re: Assembly returns...
Date: Sat, 16 May 1998 09:56:13 -0700
Message-ID: <19980516165612.AAA29559@ppp105.cartsys.com>

At 01:48  5/16/1998 GMT, Paul Derbyshire wrote:
>It's documented everywhere and generally frequently mentioned that "DJGPP C
>functions return their values in eax"..... this makes sense for many cases.
>
>
>class huge {
>public:
>  int f[900];
>  bool b[20];
>  char g[1048576];
>  int foo (void);
>}
>
>huge voodoo (bool b) {
>  //...
>  return my_huge;
>}
>
>... so how the hell does THAT fit in eax?? :-)
>
>I suppose objects bigger than 32 bits are implicitly passed by reference using
>a pointer in eax, and the temporary is deleted only after receipt of the value
>in the caller?

No. The way it works is that the caller passes an invisible first argument
which is the address where the returned aggregate should be stored. This is
useful, because in the case:

struct huge { ... };

struct huge f();

void y()
{
  struct huge h;
  h = f();
}

you end up with only one copy of huge, since the compiler will pass &h as
the address.

That's how it works in C, anyway. I don't use C++, but I imagine it is
similar except for the complications from other invisible arguments.

Btw, looking at the output of `gcc -S' helps in understanding this as well.

Nate Eldredge
nate AT cartsys DOT com



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019