[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Trouble with &&'s
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Trouble with &&'s

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Wed 04 Jun 2003 01:49 AM (UTC)
Message
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.

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Celestine   (29 posts)  [Biography] bio
Date Reply #1 on Wed 04 Jun 2003 02:52 AM (UTC)
Message
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.
[Go to top] top

Posted by Boborak   USA  (228 posts)  [Biography] bio
Date Reply #2 on Wed 04 Jun 2003 07:48 AM (UTC)
Message
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.
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #3 on Thu 05 Jun 2003 04:10 AM (UTC)
Message
Thanks :)

~Nick Cash
http://www.nick-cash.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


4,984 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]