struct comparison

Guy Harris guy at auspex.auspex.com
Sat Jul 29 03:38:48 AEST 1989


...

 >		char	bar;
 >		short	uh_oh;
 >	}
 >
 >Guess what happens?  The code breaks!!  By seemingly innocently adding
 >a field to the struct, you now have to go through and fix all the code
 >you broke.

Are you implying here that:

	1) "uh_oh" isn't supposed to be compared when you do structure
	   comparisons

or

	2) C-SEE compiles all structure comparisons into comparisons of
	   all the bytes of the structure?

If 2), I think it's been established that the *only* correct definition
of structure comparison would be member-by-member, and if that means the
structure comparison doesn't compile into e.g. a single "CMPCn"
instruction on a VAX, too bad.  While this may surprise some users of
the structure comparison construct (and, if it surprises a lot of them,
it means advocates of structure comparison had better be prepared to
educate said users), it means that adding a structure member that causes
padding to be added to a structure won't break structure comparisons.



More information about the Comp.std.c mailing list