Here's the code I had:
The macro was defined like this:
#define ERROR_RET(x) error_code=x;return false;And later I expected to call it somewhere like this:
void fun()
{
if(sth) ERROR_RET(eno);
....
}But the compiled result never turned out as expected — the logic just wasn't what I had in mind... I spent a long time checking other code, convinced there was something wrong with how the data was being processed elsewhere.
Finally it was this spot's turn, and I fixed it in tears.
The fix was easy, as shown below:
-#define ERROR_RET(x) error_code=x;return false;
+#define ERROR_RET(x) {error_code=x;return false;}Macros and inline functions are not the same — a macro simply substitutes the relevant code at compile time. So in the original code, the result of fun should have been something like this:
void fun()
{
if(sth)
error_code=x;
return false;
....
}So every place that called ERROR_RET() was returning an error unconditionally.
If I had just looked at the warning more carefully, I could have spotted it right away.
Comments
No comments yet — be the first to write one.