Bizarre Conditional Operator Problem in C++

kingofsquirrels
Unregistered
 
Post: #1
Hi all,

Today I encountered a very strange problem. It appears that the conditional '>' operator is not working correctly in the following code:

Code:
if (velocity.x() > MAX_VELOCITY_WHILE_RUNNING_ON_GROUND);
{
    printf("(velocity.x = %f) > (max_vel = %f)\n\n", velocity.x(), MAX_VELOCITY_WHILE_RUNNING_ON_GROUND);
    velocity.setX(MAX_VELOCITY_WHILE_RUNNING_ON_GROUND);
}

The output of the printf() function is: (velocity.x = -2.666667) > (max_vel = 40.000000).

velocity.x() is an inline function that simply returns a private _x variable. MAX_VELOCITY_WHILE_RUNNING_ON_GROUND is a static const float set to 40.0.

Any ideas what might be causing this? I'm using XCode 2.1 with GCC 4.0.

Thanks!
-- Will
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #2
if (velocity.x() > MAX_VELOCITY_WHILE_RUNNING_ON_GROUND);

remove the semi colon at the end and it should work.

"When you dream, there are no rules..."
Quote this message in a reply
kingofsquirrels
Unregistered
 
Post: #3
Wow, I definitely should have seen that. Thanks for the prompt reply!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Bizarre glitch... vnvrymdreglage 8 4,115 Jan 22, 2007 06:14 PM
Last Post: vnvrymdreglage
  Bizarre Bug ferum 7 3,794 Jan 20, 2007 03:26 PM
Last Post: ferum
  Conditional Compilation Errors Blacktiger 8 3,540 Jun 15, 2006 09:42 PM
Last Post: szymczyk