Compartilhar via


PREfast Warning 220 (Windows CE 5.0)

Send Feedback

220 - Implicit cast between semantically different integer types.
Additional Information: Comparing HRESULT to -1. 
Recommended Fix: Consider using SUCCEEDED or FAILED macro instead.

Note   For this warning, the SCODE type is equivalent to HRESULT.

This warning indicates that an HRESULT is being compared against an explicit, non-HRESULT value of -1, which is not a well-formed HRESULT.

It is generally best to use the SUCCEEDED or FAILED macro to test the value of an HRESULT.

In most cases, this warning is caused when code expects a function to return an integer (using –1 as a failure value) when the function returns an HRESULT.

If the actual intent is to check specifically for the E_FAIL HRESULT (for example, ignoring other possible failure values), then an explicit comparison to E_FAIL is appropriate. Otherwise, use the SUCCEEDED or FAILED macros.

Example

Defective Source

if (SomeFunction() == -1) {
    return E_FAIL;
}

return S_OK;

Corrected Source

if (FAILED(SomeFunction())) {
    return E_FAIL;
}

return S_OK;

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.