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

Attachment: signature.asc
Description: Digital signature

_______________________________________________
L4-hurd mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/l4-hurd

Reply via email to