Re: compare a large number of variables
- From: Eric Sosman <eric.sosman@xxxxxxx>
- Date: Tue, 16 Aug 2005 11:32:14 -0400
Einar wrote:
> Hi,
>
> I wonder if there is a nice bit twiddling hack to compare a large
> number of variables?
>
> If you first store them in an array, you can do:
>
> for (i = 0; i < n; i++) {
> if (array[i] != value) {
> /* array[i] differs from value, do something*/
> }
> }
>
> but I dont have the variables in an array, and would like to figure out
> a nice oneliner.
I'm not sure what you're looking for, but it might
be one of
if (a != value || b != value || ... || z != value) {
/* at least one of a,b,...,z differs from
* value, do something */
}
or
if (a != value && b != value && ... &&& z != value) {
/* all of a,b,...,z differ from value, do
* something */
}
or
if (a != value) {
/* a differs from value, do something */
}
if (b != value) {
/* b differs from value, do something */
}
...
if (z != value) {
/* z differs from value, do something */
}
or as above but with `else' before all but the first `if'
or
int *ptr[] = { &a, &b, ..., &z };
for (i = 0; i < n; ++i) {
if (*ptr[i] != value) {
/* The i'th of a,b,...,z differs from
* value, do something */
}
}
If none of these is what you're trying to do, you'll
have to explain your intent more clearly.
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: compare a large number of variables
- From: Einar
- Re: compare a large number of variables
- References:
- compare a large number of variables
- From: Einar
- compare a large number of variables
- Prev by Date: Re: compare a large number of variables
- Next by Date: Re: compare a large number of variables
- Previous by thread: Re: compare a large number of variables
- Next by thread: Re: compare a large number of variables
- Index(es):
Relevant Pages
|