Is simple assignment allowed with structs

Avery Colter avery at netcom.COM
Mon Apr 8 17:37:10 AEST 1991


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.

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 at netcom.com		{apple|claris}!netcom!avery  
(  o _ o  )   	elfcat at btr.btr.com		{decwrl|mips|sgi}!btr!elfcat
 \  /v\  /      71067.606 at compuserve.com	(415) 839-4567
  \_*-*_/
    `-'			Afternoon has gently passed me by.	    - The
  ELFCAT! 		And Evening spreads itself against the sky.   Police



More information about the Comp.lang.c mailing list