Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax Error "=="

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...

like image 844
Niro56 Avatar asked Aug 09 '12 20:08

Niro56


People also ask

How do you fix syntax error?

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.

What is a syntax error example?

Syntax errors are mistakes in using the language. Examples of syntax errors are missing a comma or a quotation mark, or misspelling a word.

What is a syntax error in C++?

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.

How do I fix invalid syntax error in Python?

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.


3 Answers

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'.

like image 51
Alan Stokes Avatar answered Oct 17 '22 20:10

Alan Stokes


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

like image 10
BigBoss Avatar answered Oct 17 '22 18:10

BigBoss


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.

like image 3
Fenster34 Avatar answered Oct 17 '22 19:10

Fenster34