Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!mcsun!inria!loria!anigbogu From: anigbogu@loria.crin.fr (Julian Anigbogu) Newsgroups: comp.lang.c Subject: Re: assigning a structure (what is happening?) Message-ID: <2216@loria.crin.fr> Date: 30 Apr 90 09:23:12 GMT References: <21734@dartvax.Dartmouth.EDU> Organization: CRIN & INRIA Lorraine, Nancy, France Lines: 27 In article <21734@dartvax.Dartmouth.EDU> pete@eleazar.dartmouth.edu (Pete Schmitt) writes: >struct inv { long number; char name[2]; } >struct inv func(s) , s; >{ > struct inv s2; > s2 = s; /* is this legal? If not why not. If so why so. */ > return(s2); /* it seems to work okay. How do the members get */ > /* their assignment? Do pointers come to play here? */ >} Assigning s to s2 is perfectly legal C so you shouldn't be surprised that returning s2 does exactly what you want. The members get their correct values because this is done in a one-to-one correspondence. That is why, the necessary condition is that both source and destination have to be of the same type. Julian ------ --------------------------------------- e-mail: anigbogu@loria.crin.fr | All opinions expressed here are | | naturally mine. However ... | ---------------------------------------- -- --------------------------------------- e-mail: anigbogu@loria.crin.fr | All opinions expressed here are | | naturally mine. However ... | ----------------------------------------