Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!spool.mu.edu!munnari.oz.au!mullauna!fraser From: fraser@mullauna.cs.mu.OZ.AU (Fraser Wilson) Newsgroups: comp.lang.c Subject: Re: Is simple assignment allowed with structs Message-ID: Date: 9 Apr 91 03:53:22 GMT Article-I.D.: mullauna.fraser.671169202 References: <15649@smoke.brl.mil> <1991Apr8.073710.22673@netcom.COM> <15766@smoke.brl.mil> Sender: news@cs.mu.oz.au Distribution: aus Lines: 27 gwyn@smoke.brl.mil (Doug Gwyn) writes: >In article <1991Apr8.073710.22673@netcom.COM> avery@netcom.COM (Avery Colter) writes: >>gwyn@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!