On Sun, 2009-05-03 at 01:43 +0200, Michael Bruck wrote:
> On Sun, May 3, 2009 at 1:03 AM, Zach Welch <z...@superlucidity.net> wrote:
> > On Sun, 2009-05-03 at 00:40 +0200, Michael Schwingen wrote:
> >> Zach Welch wrote:
> >> > If the header is required, the configure step should fail when it is not
> >> > found in the system.  The rule is to fail as early as possible.
> >> >
> >> > Which headers?
> >> >
> >> Not system headers - I was thinking about in-project headers (either
> >> user-edited, config.h or similar) that define some kind of
> >> INCLUDE_FEATURE_XXX switch. When multiple source files depend on that
> >> switch, forgetting to include it in one of them can get "interesting"
> >> results when using #ifdef.
> >
> > These type of features can be handled by --enable-feature-xxx options.
> >
> > The autoconf 2.63 info pages are great documentation.  Section 4.9.1
> > explains the config.h header fairly well, while Section 6.2.1 explains
> > the differences between #if and #ifdef:
> >
> > """
> >   Both `#if HAVE_STDBOOL_H' and `#ifdef HAVE_STDBOOL_H' will work with
> > any standard C compiler.  Some developers prefer `#if' because it is
> > easier to read, while others prefer `#ifdef' because it avoids
> > diagnostics with picky compilers like GCC with the `-Wundef' option.
> > """
> >
> > As you can imagine, I favor #ifdef for this reason.
> 
> I can't see your point. The idea of -Wundef is to warn you if you
> forgot to include a configuration file that defines variables that you
> use in your source code. And you say you favor #ifdef over #if because
> with #ifdef you will not be warned about your mistake ?!

The default action for many autotools macros either defines or undefines
the symbols associated with a certain feature (e.g. HAVE_UNISTD_H is
either defined or undefined).  In contrast, OpenOCD defines its own
features to 0 or 1.

>From GCC man page:

       -Wundef
           Warn if an undefined identifier is evaluated in an #if directive.

Using #ifdef for feature symbols that are either defined or undefined
should be preferred, as using -Wundef would cause any #if statements to
issue a warning when a required symbol has not been defined.  Thus, the
directive "#if HAVE_UNISTD_H == 1" would be wrong, without extending the
default behavior of the associated AC_CHECK_HEADERS macro to define that
symbol to 0 when it was not present).  In these cases, one must use
#ifdef for the testing of such standard features, and #if when actual
comparisons or other logic needs to be used.

I am not saying it is perfect; these are autotools and GCC conventions
and fairly common in such projects.  Your point remains valid about
#ifdef symbols, but we cannot protect the developer from themselves in
every case.  Moreover, I think that ignoring standard autotools idioms
risks confusing developers coming from other projects, myself included.

Even if it's not satisfying, does this explanation help?

Cheers,

Zach
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to