[Bug 3097] BB making easily-fixed non-portable assumptions

Joakim Tjernlund joakim.tjernlund at transmode.se
Mon Feb 7 23:02:26 UTC 2011


>
> On Mon, Feb 07, 2011 at 11:13:03PM +0100, Joakim Tjernlund wrote:
> > > On Mon, Feb 07, 2011 at 08:10:48PM +0100, Joakim Tjernlund wrote:
> > > > Relying on undef -> 0 is dangerous. Much better build with -Wundef
> > > > and fixup the errors.
> > >
> > > How is this dangerous? Undef -> 0 is part of the C language at least
> > > since C89, and perhaps before that. Nobody is using pre-ANSI C
> > > compilers, and I guarantee if you try to compile Busybox with a
> > > pre-ANSI compiler, you will encounter much bigger problems than the
> > > preprocessor failing to convert undefined symbols to 0 when evaluating
> > > #if...
> >
> > code sometime assumes/needs a symbol to be defined to some
> > value or it is an error. Undefined syms redefined to 0
> > may break such code silently.
>
> I think you're trying to apply some general dogmatic rule without
> understanding it. These two preprocessor directives:
>
> #if defined(FOO) && (FOO > BAR)
> #if FOO > BAR

Assume BAR = -1, then do it again.

>
> are absolutely identical in behavior. Neither "redefines" FOO to 0. In
> both cases, FOO gets expanded to 0 for the evaluation of this line. If
> you really cared about distinguishing the cases of undefined versus
> defined-as-zero, you would need two separate #if's:
>
> #if !defined(FOO)
> #error FOO is not defined.
> #endif
> #if FOO > BAR

This is my point, write your code so that -Wundef doesn't make trouble.

So again, add -Wundef and fixup any code that throws warnings so not
ill written code will pass silently

>
> However, in the code in question, this is completely a non-issue.
>
> In the case of testing whether you're on a system that conforms to
> POSIX 2008, #if _POSIX_VERSION >= 200809L is the correct (and
> recommended by the standard) test.

So make pass with -Wundef so you can find any potential misuses.



More information about the busybox mailing list