this is part of my code to my game engine that I am working on. When I build/debug the code, it stops with a compiler error: "Camera.cpp(70): error C2059: syntax error : '==' " and line 70 is the
if ( near == far )
line. It also happens on line 75:
(if near == NULL || far == NULL)
bool Camera::SetClippingPlanes( float near, float far )
{
if (near == far) //Line 70(First Error)
{
MessageBox(NULL, L"ERROR: The far and near clipping planes cannot be equal!", L"Error", MB_OK | MB_ICONERROR);
return false;
}
else
{
if (near == NULL || far == NULL) //Line 75(Second Error)
{
MessageBox(NULL, L"ERROR: Near and/or Far clipping planes are null!", L"Error", MB_OK | MB_ICONERROR);
return false;
}
else
{
nearPane = near;
farPane = far;
return true;
}
}
}
I have other functions which use the == operator in the same way, but they do not receive an error. Thanks if you have any suggestions...
How to Fix It: If a syntax error appears, check to make sure that the parentheses are matched up correctly. If one end is missing or lined up incorrectly, then type in the correction and check to make sure that the code can be compiled. Keeping the code as organized as possible also helps.
Syntax errors are mistakes in using the language. Examples of syntax errors are missing a comma or a quotation mark, or misspelling a word.
Syntax errors: Errors that occur when you violate the rules of writing C/C++ syntax are known as syntax errors. This compiler error indicates something that must be fixed before the code can be compiled. All these errors are detected by compiler and thus are known as compile-time errors.
You can clear up this invalid syntax in Python by switching out the semicolon for a colon. Here, once again, the error message is very helpful in telling you exactly what is wrong with the line.
Many years ago (in a galaxy far, far away) near
and far
were keywords. It looks like your compiler still thinks they are - it's probably trying to be helpful.
You either need to pick different names, or figure out how to turn off this particular backward-compatible 'feature'.
You are coding for windows and in windows if you include windows.h or a file that include it( and certainly you include it, because you have a call to MessageBox ) then far
and near
are both defined in windef.h
and you can't use them as variable names
It is also dangerous to compare floats with ==. Its not possible to represent every number with absolute precision. I believe the main ieee floating implementations are only good to 6 significant places. You'll find two ways or calculating what should be the same number will be out by 0.000001 or less and therefore wont be equal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With