struct assignment question
Julian ANIGBOGU
anigbogu at loria.crin.fr
Thu Mar 15 19:43:02 AEST 1990
In article <31530005 at hpcvia.CV.HP.COM> brianh at 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 at loria.crin.fr | All opinions expressed here are |
| naturally mine. However ... |
----------------------------------------
More information about the Comp.lang.c
mailing list