Go to Post When more STEM teams exist outside schools than in them, that will be one indication that a true cultural change has occurred. - gblake [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Spotlight this post!  
Unread 26-01-2005, 17:41
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Weird problem with if statements

Quote:
Originally Posted by Don Reid
The compilers don't complain because it is legal and sometimes done on purpose.
To add on to what Don said, if you want to get the compiler to complain, you can try to get in the habit of doing the following.

if(1 == x)
{
}
instead of
if(x == 1)
{
}

With the correct comparison syntax (as written), you should see no difference when you compile, but if you were to mistakenly put a single '=' instead of a double, you would see the a syntax error. This is because it tries to assign the value of x to 1. Since you don't have permission to write to 1, you get the error.

Note that if you were to be comparing two variables, instead of a variable to a constant number, you wouldn't see the syntax error because you would be allowed to write one variable into another (in most cases).

There are some people that use this as their coding standard. I personally don't use it, but it may be something that helps you get in the habit of remembering the == when comparing.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming Problem: Extremely Frustrating chantilly_team Programming 19 12-02-2005 23:00
Physics Problem Venkatesh Math and Science 13 30-11-2004 20:30
Weird Output from Dashboard Port Ian W. Programming 9 06-03-2004 21:33
The problem with scouting... archiver 2001 10 23-06-2002 23:49
Major problem with chipphua motors aka Scott White Motors 18 19-03-2002 19:44


All times are GMT -5. The time now is 04:39.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi