| |
comp.lang.c |
Let's assume that a and b have the same basic data type On many platforms it is possible to replace the What are the conditions that this will not yield the Can someone give (an) implementation example(s), where The background is the wish of fast and easy comparison typedef struct test { TEST sa,sb; Is it possible to construct such a general system to work Would it be possible to construct an #if-expression #if (expression_memcmp_will_do_the_job) to react to the different situations? --
(e.g. int, long, float, double ...).
comparisions
a==b
a!=b
by
memcmp(&a,&b,sizeof(a))==0
memcmp(&a,&b,sizeof(a))
desired results?
the reasons for this behaviour can be seen?
of multicomponent structures (within a perfect hash system):
char ...
int ...
float ...
...
} TEST;
memset(&sa,'\0',sizeof(TEST)); /* or TestClear(&sa); */
memset(&sb,'\0',sizeof(TEST)); /* or TestClear(&sb); */
...
any standard component assignment. /* or TestSetComponent(&sa,comp) */
...
memcmp(&sa,&sb,sizeof(TEST));
in a portable way on all platforms?
TestEqu(psa,psb) (memcmp(psa,psb,sizeof(TEST))==0)
#else
(psa->comp1==psb->comp2 && psa->comp2==psb->comp2 && .... )
#endif
Helmut Leitner leit...@hls.via.at
Graz, Austria www.hls-software.com