Is simple assignment allowed with structs
Fraser Wilson
fraser at mullauna.cs.mu.OZ.AU
Tue Apr 9 13:53:22 AEST 1991
gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <1991Apr8.073710.22673 at netcom.COM> avery at netcom.COM (Avery Colter) writes:
>>gwyn at smoke.brl.mil (Doug Gwyn) writes:
>>>>I tried adding two structs and that did not work.
>>>Of course not. What would it mean?
>>Now, of course, there is nothing stopping you from making a little function
>>to "add" two structs of the same type and return a struct of this type
>>as the function result; the body of the function would just be field-by-field
>>simple addition of the parallel field values in the input structs.
>This is not always possible, for example for pointer members.
>Even if it were possible, it may not correctly represent an algebraic
>"addition" of the quantities represented by the structures, although
>often it would.
I think what was meant here is to write a unique addition function for
each struct. Ie, you would only write meaningful addition functions,
and you wouldn't add pointers together. So yes, it is always possible.
Fraser.
-----------------------------------------------------------------------------
For which of thee is made upon
The plan of Long Ago?
Tho' Wither W'ere in Sacred Sea
The Horn of Death shall blow!
More information about the Comp.lang.c
mailing list