Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!nuchat!moray!urchin!f506.n106.z1.fidonet.org!Roy.Browning From: Roy.Browning@f506.n106.z1.fidonet.org (Roy Browning) Newsgroups: comp.lang.c Subject: Question about return values of type struct Message-ID: <18164.24D52BE2@urchin.fidonet.org> Date: 31 Jul 89 03:51:21 GMT Sender: ufgate@urchin.fidonet.org (newsout1.26) Organization: FidoNet node 1:106/506 - Fulcrum's Edge, Spring TX Lines: 25 > From: u-tholly@wasatch.utah.edu (Troy Holly) > Date: 29 Jul 89 04:34:41 GMT > Organization: University of Utah CS Dept > Message-ID: <2264@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