Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!ames!vsi1!daver!dlb!netcom!avery From: avery@netcom.COM (Avery Colter) Newsgroups: comp.lang.c Subject: Re: Is simple assignment allowed with structs Message-ID: <1991Apr8.073710.22673@netcom.COM> Date: 8 Apr 91 07:37:10 GMT References: <15649@smoke.brl.mil> Organization: Netcom - Online Communication Services UNIX System {408 241-9760 guest} Lines: 25 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. The reason assignment works is that structs of the same type are of the same size in bytes, and all have their fields at the same byte offsets, so that assignment would just mean copying the range of bytes holding the rvalued struct into the area holding the lvalued struct. -- ^ ^ Avery Ray Colter /^\___/^\ avery@netcom.com {apple|claris}!netcom!avery ( o _ o ) elfcat@btr.btr.com {decwrl|mips|sgi}!btr!elfcat \ /v\ / 71067.606@compuserve.com (415) 839-4567 \_*-*_/ `-' Afternoon has gently passed me by. - The ELFCAT! And Evening spreads itself against the sky. Police