C++ no equal sign but compiles without assigning value

If ERR_NOT_OK is defined as -41, then your

ret_value ERR_NOT_OK;

is substituted with

ret_value -41;

which is a valid expression statement, even though it is effectively a no-op. What was originally intended as unary - gets interpreted as binary - in this context.

This is why it is a good idea to define it as

#define ERR_NOT_OK (-41)

Leave a Comment