Newsgroups: comp.lang.c
From: usur...@euronet.nl (Paul Mesken)
Date: 1999/06/28
Subject: Re: Expert-Q: (a!=b) != memcmp(&a,&b,sizeof a) ?
On Mon, 28 Jun 1999 10:56:20 +0200, Helmut Leitner
<leit...@hls.via.at> wrote: If a and b are of the same basic data type then you wouldn't do this. >Let's assume that a and b have the same basic data type >(e.g. int, long, float, double ...). >On many platforms it is possible to replace the It's ugly and probably slower. Besides: what if a and/or b have the storage class specifier "register"? Then it is illegal to use the address-of operator on them. >What are the conditions that this will not yield the If they are not of the same basic type for example. Unlike using the >desired results? equality operators, the memcmp version will not convert them. This might result in inequality while the values of a and b are the same. It might look as if the memcmp version can do "clever" comparisons However: >The background is the wish of fast and easy comparison Yes, you first set all char's of the structures to zero. This solves >of multicomponent structures (within a perfect hash system): > typedef struct test { > TEST sa,sb; the problem of the "uninitialized padding". >Is it possible to construct such a general system to work In this particular case I don't see why not. >in a portable way on all platforms? >Would it be possible to construct an #if-expression I don't see how the expression should look like. Your solution works > #if (expression_memcmp_will_do_the_job) >to react to the different situations? as long as you take care to initialize _all_ char's of the structures to avoid the "inequal padding value" problem and make sure that your a and b are of the same structure type. You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||