Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!husc6!purdue!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c Subject: Re: Useful macro...or dangerous?? Message-ID: <487@goofy.megatest.UUCP> Date: 28 Apr 88 04:40:01 GMT References: <221@raunvis.UUCP> Organization: Megatest Corporation, San Jose, Ca Lines: 35 in article <221@raunvis.UUCP>, kjartan@raunvis.UUCP (Kjartan Pier Emilsson Jardedlisfraedi) says: > ... > As I quickly became tired of gigantic IF tests, I decided > to build some sort of equality macro, and came down on the following > solution which seems to work. ... > > #define EQ(A,B) equal(A,B,sizeof(*(A))) > ... > I herewith submit my possible blunders to the Blowtorches of the Net. > > Kjartan Pierre Emilsson, Reykjavik, ICELAND I admire your courage. No torch here, so relax. As Dustin Hoffman said in Marathon Man, "It's not safe." Due to packing alignment within the struct, there may be some garbage bits "in the cracks". You could get a "not equal" result when in fact, the structures should compare as equal. If you use this technique, be sure that you bzero() structures when you allocate them. Don't be too suprised if you, or somebody else, forgets to do so, and the world, as we know it, comes to an end. Also, use the C-library function bcmp() rather than your equal(). Good luck, Dave J.