struct comparison

Guy Harris guy at auspex.auspex.com
Sat Jul 22 04:22:56 AEST 1989


>Right, the component-by-component comparison is much safer, and is the 
>natural approach for Ada.  Given C's low-level approach, though, I did 
>not want to rule out from discussion a simplistic compare-all-bytes 
>implementation.

*I'd* rule it out, because it can give the wrong answer, but if you
don't care about getting the right answer, or know that in some
particular case it will never give the wrong answer, and you *really*
want a simplistic compare-all-bytes implementation, you can use "memcpy"
- which may be inlined in some implementations. 

If you want a component-by-component comparison, you can write it
yourself, obviously, or wrap it in a macro if you use it a lot.  Perhaps
not as convenient as having the compiler do it for you, but I'd find it
more convenient than, for every structure, deciding whether a compiler
notion of structure comparison would really do what I wanted (e.g., the
question of "do you compare pointer values or do you compare the values
to which they point), or would even work at all (e.g., a structure with
unions).



More information about the Comp.std.c mailing list