do ... while(0) optimization problem

Detlef Vollmann dv at vollmann.ch
Mon Jan 7 08:37:36 UTC 2008


Mike Frysinger wrote:
> so fix your gcc ?  the point of do { ... } while (0) is to provide proper
> wrapping context that can be used anywhere that a single statement can.
I know.  I personally prefer the comma operator, is possible, as this
gives you a true expression (like a function call that is mimicked
by the macro expansion).

>  sane
> gcc will expand all of the code within without the do/while part because it's
> a nop.
The preprocessor will expand always everything, and the optimizer
might remove anything that it believes make no difference on the
external behaviour.

The problem here might actually be the PTR_TO_GLOBALS, as the
compiler thinks that ptr_to_globals can't be changed anyway, so
the assignment might be optimized away...

> you could always compare the disassembly output, but considering how ancient
> your gcc is, that sounds like a waste of time
Point taken, but maybe the problem is not specific to this version
of this compiler.

  Detlef

-- 
Detlef Vollmann   vollmann engineering gmbh
Linux and C++ for Embedded Systems    http://www.vollmann.ch/



More information about the busybox mailing list