[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: IDL issue - struct return vs. cap return
From: |
Pierre THIERRY |
Subject: |
Re: IDL issue - struct return vs. cap return |
Date: |
Tue, 10 Jul 2007 00:13:37 +0200 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
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
--
address@hidden
OpenPGP 0xD9D50D8A
signature.asc
Description: Digital signature
- Re: IDL issue, (continued)
- Re: IDL issue, Michal Suchanek, 2007/07/10
Re: IDL issue, Neal H. Walfield, 2007/07/09
Re: IDL issue - struct return vs. cap return, Jonathan S. Shapiro, 2007/07/09
Re: IDL issue - struct return vs. cap return, Jonathan S. Shapiro, 2007/07/10
Re: IDL issue - struct return vs. cap return, Neal H. Walfield, 2007/07/10
Re: IDL issue - struct return vs. cap return, Jonathan S. Shapiro, 2007/07/10
Re: IDL issue - struct return vs. cap return, Neal H. Walfield, 2007/07/10
Re: IDL issue - struct return vs. cap return, Jonathan S. Shapiro, 2007/07/10
Re: IDL issue - struct return vs. cap return, Jonathan S. Shapiro, 2007/07/10