Messages in this thread | | | Date | Tue, 31 Aug 2004 09:52:30 -0700 (PDT) | From | Linus Torvalds <> | Subject | Re: What policy for BUG_ON()? |
| |
On Tue, 31 Aug 2004, Albert Cahalan wrote: > > The normal expectation for non-debug builds > would be this: > > #define BUG_ON(x)
No, this is bad, for one big reason: it generates compiler warnings if 'x' happens to be the only thing that uses some value. You get things like "unused variable 'mode'" etc in perfectly good code.
For example, the code might look something like
int count = 0;
for_each_online_cpu(cpu) { ... do something .. .. update count .. }
BUG_ON(!count);
and if you now compile on UP and with debugging enabled, the compiler might complain that you're computing "count" but never _using_ the value.
This is generally why you should have macros like this not become empty, but become something that the compiler can compile away. Which is why I'd much rather see
#define BUG_ON(x) (void)(x)
regardless of any side-effect issues - it's a way to let the compiler optimize the thing away, but still show that something was used at least "conceptually"..
Linus - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |