Re: compare a large number of variables





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

.



Relevant Pages

  • Re: compare a large number of variables
    ... Einar wrote: ... > I wonder if there is a nice bit twiddling hack to compare a large ... > but I dont have the variables in an array, and would like to figure out ...
    (comp.lang.c)
  • Re: compare a large number of variables
    ... Einar wrote: ... > I wonder if there is a nice bit twiddling hack to compare a large ... > but I dont have the variables in an array, and would like to figure out ...
    (comp.lang.c)
  • compare a large number of variables
    ... I wonder if there is a nice bit twiddling hack to compare a large ... If you first store them in an array, ...
    (comp.lang.c)
  • Re: PHP - I give up.
    ... /* Compares A and B, given auxiliary data AUX, and returns a ... typedef int algo_predicate_func (const void *data, ... SIZE bytes each, using COMPARE for comparisons. ... first element in ARRAY that matches TARGET, ...
    (comp.programming)
  • Re: working with byte arrays
    ... array before the values are assigned. ... Before I allways thought that ALL bytearray operations require a redim, ... >> If you know a better way to compare two byte arrays then please let me ... > Public Sub ShareMemoryViaArray(ByVal ArrayPtr As Long, ...
    (microsoft.public.vb.general.discussion)