Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!eru!luth!sunic!mcsun!inria!loria!anigbogu From: anigbogu@loria.crin.fr (Julian ANIGBOGU) Newsgroups: comp.lang.c Subject: Re: struct assignment question Message-ID: <1833@loria.crin.fr> Date: 15 Mar 90 09:43:02 GMT References: <31530005@hpcvia.CV.HP.COM> Organization: CRIN & INRIA Lorraine, Nancy, France Lines: 39 In article <31530005@hpcvia.CV.HP.COM> brianh@hpcvia.CV.HP.COM (brian_helterline) writes: >I have a simple question: Can you assign a struct like any other data type? >An example: > >struct { > int a; > int b; > long c; > } var1, var2; > > var1.a = 3; var1.b = 4; var1.c = 15L; > > var2 = var1; /* <--- is this legal? */ >I was told it was not. Is this always the case? What does ANSI say? > >Thanks the info. Your assignment of var1 to var2 is perfectly legal !! I guess somebody has been reading old K&R lately. This is the second time in as many days that stucture assignments are creating problems. Any compiler that doesn't support this certainly needs a resting place in a museum! When in doubt about such problems and a C book is not handy, go ahead as you did above, add a print statement since you know what results you expect and see what your compiler does. I do that myself from time to time because there are certain problems that are not covered in textbooks. Evidently we can't expect authors to know about every possible usage of a particular C facility: it's normally applications that determine what facilities a programmer uses. Julian -- --------------------------------------- e-mail: anigbogu@loria.crin.fr | All opinions expressed here are | | naturally mine. However ... | ----------------------------------------