What You Can Learn from Compiler Warnings

What You Can Learn from Compiler Warnings

The following code has a subtle bug. Can you detect it?

 DWORD ErrCode = GetLastError(); // Retrieve the error codeif (!ErrCode==ERROR_FILE_NOT_FOUND) // warning on this line

Although the compiler cannot guess the programmer’s intent, it issues a warning message that provides a cue:

 warning C4806: '==' : unsafe operation: no value of type 'bool'

 promoted to type 'const long' can equal the given constant.

The compiler says it cannot safely compare a variable of type bool and const long. Wait a minute


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist