Question about return values of type struct

Roy Browning Roy.Browning at f506.n106.z1.fidonet.org
Mon Jul 31 13:51:21 AEST 1989


 > From: u-tholly at wasatch.utah.edu (Troy Holly)
 > Date: 29 Jul 89 04:34:41 GMT
 > Organization: University of Utah CS Dept
 > Message-ID: <2264 at wasatch.utah.edu>

 > mystruct copyfoo(foo1) mystruct foo1; {
 >         mystruct foo2;
 >         return ( foo2 );

 > main () {
 >         mystruct foo3, foo4;
 >         foo3 = copyfoo(foo4);

 > I am worried about this code.  I have more or less inherited it.  Does
 > the assignment to foo3 in main() need to be done with pointers, i.e.,  
 > should copyfoo() return a pointer to struct instead of a struct?  Like

Troy:

        Function "copyfoo()" is indeed returning a structure and that structure is being COPIED to "foo3" in the main function.  Thus after the assignment you will be accessing the structure defined in "main()" not in "copyfoo()".  Do an assembly dump if you wish to confirm that the structure is copied.

                                 Intermediate 'C'eer,

                                   Roy Browning



More information about the Comp.lang.c mailing list