Re:Re: Why do not work?, is the same.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> The statement tmp.str = marca(...).str  copies the CONTENTS of the string 
> value, returned by the function which is ok, since when returning a variable  
> of type struct Marca is shipped through the stack.
> 
> The second form in block B this variable will also ships through the stack.  
> This time not the CONTENTS of the string is copied but the pointer to str 
> field of the variable that has been created on the stack frame is given as an 
> argument to printf.  The problem is, that while printf executes the stack 
> frame contains the printf arguments.  The stack frame of the previously 
> executed marca function has been deleted at this time.  But you still point 
> to this stack frame by trading the str field pointer.
> 
> You should be carefull exchanging such objects through the stack.  It is much 
> better to trade object references:
> 
> int marca( struct Marca* x, const char* y, int v) -> operate on x->str
> and use the integer return value as an error indicator.  You are on the save 
> side. 
> 
> int main (...) {
> 	int ret=0;
> 	struct Marca marca;
> 
> 	if ( 0 == (ret=marca(&marca,"bla.html",1))  ) printf( "OK=%s\n", marca.str);
> 	return ret;
> }

Thanks,

OK field pointers are missed by GCC while evaluate mother function.

But functions that return (char *) works shipping through the stack, like ctime,
printf("%s",ctime(...));

Is is incredible but I have a function that return (char *) and works in printf(); 
but fails in other stdio functions, in this case only the last function evaluated is returned to all arguments.

???printf("%s%s%s",a(1),a(2),a(3));

In this case printf() works but other functions print in %s only the value of a(1).

I need return  char a[size]  to ??printf functions, but strange (for me) GCC  method said my that I have no way.

Thanks again.



 

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux