Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] logic error with code hosted on your servers



On Sun, 14 Mar 2004 02:00:54 -0800 (PST)
mohr@example.com wrote:

> if ((context = RkwInitialize( (char *)ddname )) < 0)
> 
> As you can see, this comparison will always fail,
That's not true, you should review the C grammar.

> causing the program to
> exit prematurely (giving an extremely nondescript error).  This line
> should read:
> 
> if ((context == RkwInitialize( (char *)ddname )) < 0)
While the RkInitialize function returns either 0 or -1 according to the
manage, RkwInitialize might return something more complex, otherwise using
a comparison against context wouldn't make much sense. And the above == is
a boolean comparison that is either TRUE or FALSE and there is no reason
you would want to use '<' to compare that value.

Here is an example that will help you understand the scenario:

int returns_zero() {
  return 0;
}
int returns_one() {
  return 1;
}
 
int main (int argc, char **argv) {
    int retval;
    if ((retval = returns_zero()) == 0) printf("OK\n");
    if ((retval = returns_one()) == 1) printf("OK\n");
    if ((retval = returns_zero()) == 1) printf("NG\n");
    if ((retval = returns_one()) == 0) printf("NG\n");
}


> Which will perform the comparison correctly and allow the server to run.
I'm not the author but I think the error is somewhere else.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links