question on common error-handling idiom

From: Chris Friesen
Date: Tue Nov 02 2004 - 15:16:32 EST



There's something I've been wondering about for a while. There is a lot of code in linux that looks something like this:


err = -ERRORCODE
if (error condition)
goto out;


While nice to read, it would seem that it might be more efficient to do the following:

if (error condition) {
err = -ERRORCODE;
goto out;
}


Is there any particular reason why the former is preferred? Is the compiler smart enough to optimize away the additional write in the non-error path?

Chris
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/