2008/1/6, Mike Frysinger <[EMAIL PROTECTED]>:
> On Sunday 06 January 2008, Loïc Grenié wrote:
> > 2008/1/6, Mike Frysinger <[EMAIL PROTECTED]>:
> > > On Sunday 06 January 2008, Detlef Vollmann wrote:
> > > > in util-linux/fdisk.c, the macro
> > > >
> > > > #define INIT_G() do { \
> > > > PTR_TO_GLOBALS = xzalloc(sizeof(G)); \
> > > > sector_size = DEFAULT_SECTOR_SIZE; \
> > > > sector_offset = 1; \
> > > > g_partitions = 4; \
> > > > display_in_cyl_units = 1; \
> > > > units_per_sector = 1; \
> > > > } while (0)
> > > >
> > > > seems to get partly optimized away in my gcc (GCC) 3.2.2.
> > > > I get a segmentation fault and it turns out that ptr_to_globals is 0.
> > >
> > > 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.
> > > sane gcc will expand all of the code within without the do/while part
> > > because it's a nop.
> > >
> > > > Rewriting the macro to
> > > >
> > > > #define INIT_G() ( \
> > > > PTR_TO_GLOBALS = xzalloc(sizeof(G)), \
> > > > sector_size = DEFAULT_SECTOR_SIZE, \
> > > > sector_offset = 1, \
> > > > g_partitions = 4, \
> > > > display_in_cyl_units = 1, \
> > > > units_per_sector = 1)
> > > >
> > > > works fine...
> > >
> > > you could always compare the disassembly output, but considering how
> > > ancient your gcc is, that sounds like a waste of time
> >
> > You can also rewrite the macro
> >
> > do {
> > statements;
> > break;
> > } while(1)
> >
> > Ancient SunOS' cc's are known to break the do { } while(0); construct.
> > It does not break the preceeding one. I don't remember anything about
> > gcc though.
>
> that'd be interesting to see if it makes a difference here ... but considering
> the common convention is (0) and the target busybox environment is not
> old/busted SunOS, i dont think we should be catering to busted compilers.
Sorry I was not clear enough: you are perfectly right that the compiler
is broken and should be changed. However, another solution for this
problem in the case of the OP was to change the macro as indicated.
I do not think it would be a good idea to change busybox: do { } while(0)
is correct and works for nearly every compiler.
Loïc Grenié
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox