Path: utzoo!mnetor!uunet!mcvax!hafro!krafla!raunvis!kjartan From: kjartan@raunvis.UUCP (Kjartan Pier Emilsson Jardedlisfraedi) Newsgroups: comp.lang.c Subject: Useful macro...or dangerous?? Message-ID: <221@raunvis.UUCP> Date: 26 Apr 88 14:42:19 GMT Organization: Science Inst. Univ. of Iceland Lines: 50 Keywords: macro Hello world! This sentence is meant as an introducing one. In my work I have often felt the need to test the equality of two structures, for example test the equality of a Color structure and so on. 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. (Of course if some members of a structure are pointers, then the equal() function returns 0 if the pointers do not point to the same adress). Now I would very much like to know whether this is a foolproof way to test equality of structures, or is there a hidden nasty little fellow who eludes me. #define EQ(A,B) equal(A,B,sizeof(*(A))) typedef struct { ... ... }ANYSTRUCTURE; main(){ ANYSTRUCTURE some,thing,or,the,*other ... ... if( EQ(&some,other) ) printf("yupyup\n"); else if( EQ(&thing,&or) ) printf("spulft.\n"); ... ... etc. } equal(a,b,size) char *a,*b; long int size; { while(*(a+si-1)== *(b+si-1) && si>0) si--; if(si==0) return(1); else return(0); } I herewith submit my possible blunders to the Blowtorches of the Net. Kjartan Pierre Emilsson, Reykjavik, ICELAND