Re: IDL issue - struct return vs. cap return

Pierre THIERRY <[email protected]>
Newsgroups gmane.os.hurd.l4
Message-ID <[email protected]>
Scribit Neal H. Walfield dies 09/07/2007 hora 23:24:
> Consider:
> 
>   #include <string.h>
>   #include <stdio.h>
>   
>   struct foo
>   {
>     char *p;
>     char s[100000];
>   };
>   
>   struct foo bar (void)
>   {
>     struct foo foo;
>     foo.p = foo.s;
>     return foo;
>   }
>   
>   int
>   main ()
>   {
>     struct foo foo;
>     foo.p = foo.s;
>   
>     printf ("before: %x\n", foo.p);
>     foo = bar ();
>     printf ("after: %x\n", foo.p);
>   }
> 
>   $ ./foo
>   before: 7339c5c8
>   after: 7336b848

That doesn't mean GCC isn't doing the mentioned transformation for
return values. The fact that the return value is stored in a variable
passed by reference doesn't mean the previous value in this variable
will be used in any way.

Your bar() will still allocate a new foo struct and the compiled
function could then amounts to something like:

   void bar (struct foo &return)
   {
     struct foo foo;
     foo.p = foo.s;
     return = foo;
   }

Alternatively,
Pierre
-- 
[email protected]
OpenPGP 0xD9D50D8A

_______________________________________________
L4-hurd mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/l4-hurd
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGkrMRxe13INnVDYoRAo7nAJoC+iTXqmYOFvBF3iWGyfcaQK4RRQCgtI1S
mP9yvXpRR0StM4sPtldoPTE=
=lBa5
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.