bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Fix use of ENABLE_NLS (which is not always defined)


From: Grégoire Sutre
Subject: Re: [PATCH] Fix use of ENABLE_NLS (which is not always defined)
Date: Thu, 18 Mar 2010 16:45:46 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20091027)

Eric Blake wrote:
On 03/17/2010 06:58 PM, Grégoire Sutre wrote:
Just out of curiosity: is there a reason for this behavior of
AC_CHECK_DECLS, which, quoting the manual, is unlike the other
‘AC_CHECK_*S’ macros?

Yes - it looks cleaner to write code like:

if (CONDITION)
  do_something ();

than

#if CONDITION
  do_something ();
#endif

but that only works if CONDITION is always defined to 0 or 1.

I see.  And the compiled file should be the same if the compiler
performs (even simple) dead-code elimination.

In
general, we prefer to avoid #if inside function bodies; it is easier to
read code where all the #if have been factored out to file scope level
and function bodies are straight-line code.

I agree that functions can be difficult to read when they contain #if
conditions.  However, these cannot be avoided when the types of the
function's local variables depend on them.

Newer autoconf macros
follow this style, and gnulib continues it for most macros defined by
gnulib.  And even for the older autoconf macros which did not follow
this paradigm, it's not too hard to do:

#ifndef CONDITION
# define CONDITION
#endif

at the top of the file, to once again keep #if out of function bodies.

Good to know, thanks!

Grégoire




reply via email to

[Prev in Thread] Current Thread [Next in Thread]