[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Avoid Unintentional Errors

If the Possible Errors option is on, the compiler checks for some common typographical mistakes that are legal C syntax but that may have unwanted side effects, such as putting in unintended semicolons or confusing = and ==. The compiler generates a warning if it encounters one of these:
if (a=b) f(); // WARNING: a=b is an assignment
if ((a=b)!=0) f(); // OK: (a=b)!=0 is a comparison, no warning
if (a==b) f(); // OK: (a==b) is a comparison, no warning
An equal comparison in a statement that contains a single expression. This check is useful if you frequently use == when you meant to use =. For example:
a == 0; // WARNING: This is a comparison.
a = 0; // OK: This is an assignment, no warning
A semicolon (;) directly after a while, if, or for statement. For example, the statement generates a warning and is probably an unintended infinite loop:
while (i++); // WARNING: Unintended infinite loop
If you intended to create an infinite loop, put white space or a comment between the while statement and the semicolon. For example, these statements do not generate errors or warnings, and ensure that you will win the hearts of everyone using your software when the code is executed.
while (i++) ; // OK: White space separation, no warning
while (i++) /*: Comment separation, no warning */ ;
The Possible Errors option corresponds to the pragma warn_possunwant, described at "warn_possunwant." To check whether this option is on, use __option (warn_possunwant). See "Checking Options" for information on how to use this directive.
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 17, 2000