Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Koobazaur

IF() doesn't like the (x) ? y : z statement?

This topic is 5324 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've tried doing something like this:
int x;
int number;
int array;

//define all three variables


if(x < (number>0) ? array[number-1] : 0)
{
//do stuff

}
and to my surprise - it didn't work! It compiled but the if statement didn't work very well... when I replaced it with:
int x;
int number;
int array;

//define all three variables


if(number>0}
{
_if(x<arra[number-1])
_{
_//do stuff

_}
}
else
{
_if(x<0)
_{
_//do stuff

_}
}
it worked fine... [edited by - Koobazaur on February 28, 2004 5:25:33 PM] [edited by - Koobazaur on February 28, 2004 5:25:53 PM]

Share this post


Link to post
Share on other sites
Advertisement
This is an operator precedence issue. Change:

if (x < (number>0) ? array[number-1] : 0) to
if (x < ((number>0) ? array[number-1] : 0))

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!