Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.std.c Subject: Re: struct comparison Message-ID: <2266@auspex.auspex.com> Date: 21 Jul 89 18:22:56 GMT References: <2874@solo3.cs.vu.nl> <1989Jul14.155312.2063@utzoo.uucp> <2878@kappl.cs.vu.nl> <1989Jul15.210821.7950@utzoo.uucp> <167@ssp1.idca.tds.philips.nl> <1989Jul18.020424.2392@utzoo.uucp> <2335@trantor.harris-atd.com> <2261@auspex.auspex.com> <2361@trantor.harris Reply-To: guy@auspex.auspex.com (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 19 >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).