Trouble with &&'s

Posted by Nick Cash on Wed 04 Jun 2003 01:49 AM — 4 posts, 18,480 views.

USA #0
Well, in addition to my other problem, I've got this one. Now these are just warnings and it still compiles, but to say the least they are annoying.

space.c: 10744: warning: suggest parentheses around && within ||

I know enough to tell what its saying, on line 10744 is the warning in space.c. So here is the section of code it seems to have trouble with:

if (arg1 != "ST-A1" || arg1 != "MID-C1" && !str_cmp("TAC",ch->pcdata->clan->name) )
{
send_to_char("You cannot order that!\n", ch );
send_to_char("Consult HELP TACMODELS\n\r, ch );
return;
}

Previous code checks to make sure they have a clan and such, and previous code does other checks, so its not a problem with something such as they don't have a clan or something.

Arg1 is defined as char and to me this seems like it should work, yet it still doesn't like it. Well, anyways, I was just wondering how I would rearange the if statement so that it wouldn't have the warning.

Thanks for any and all help.
#1
It's just rather vague to the compiler. Let's call the three things you want to test A, B, and C. The way you have it, it's something like:
A or B and C

That could mean either
A or (combination of B and C)

or

(either A or B) and C

I believe that you can simply add parenthesis around the ones you want to group. So for the first case where it was either A or the combination of both B and C, you would do:
A || (B && C)

The other one should look something like:
(A || B) && C

I'm not 100% sure on this though. I usually try to rewrite it and just put one if inside of another.
USA #2
It's just looking for this:

if ((arg1 != "ST-A1" || arg1 != "MID-C1") && !str_cmp("TAC",ch->pcdata->clan->name) )

The code would likely work without them in this case as the compilers default action would do what I believe you intended it to do. But, the compiler is simply asking you to clarify the logical statement you presented.
USA #3
Thanks :)