lkml.org 
[lkml]   [2004]   [Aug]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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/

\
 
 \ /
  Last update: 2009-11-18 23:46    [W:0.055 / U:0.520 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site