Porting style

David Champion dgc at uchicago.edu
Wed Jan 15 18:10:02 CET 2003


* On 2003.01.15, in <877kd696oh.fsf at alberti.g10code.de>,
*	"Werner Koch" <wk at gnupg.org> wrote:
> - #ifdef HAVE_PGP
> -   if (foo)
> -      bar ();
> - #endif
> 
> +   if (HAVE_PGP && foo)
> +      bar ();
> 
> Given that HAVE_PGP is defined to 0 or 1.  Because HAVE_PGP is a
> constant, the compiler will either eliminate the entire construct or
> eliminate the "HAVE_PGP &&" term.  It is obvious that the code is
> easier readable when you use these constructs with heavily nested

Heavier nesting is more difficult to read no matter whether it's
preprocessor code or the actual language in use. (I don't like LISP,
either.) Yet I'd actually disagree that your second example is more
readable than the first, though. I think it less so, because HAVE_PGP
and foo are of a different nature. It's useful for the person reading
the code, whether developer, auditor, or casual browser, to be find
like items associated. But you've satisified my curiosity about the GPG
team's preferences, so that's good enough for me.


> Well, it does of course not work when there are functions which are
> not available on some OSes - a silly stub function would do though.

Agreed: stubs are good. But you have to ifdef those (or something)
somewhere; hence my inquiry. :)

Ifdefs are better to me than, for example, having your Makefile contain
all the intelligence about various operating systems, and include
different versions of the OS-dependent file for different platforms. I'm
glad you don't rule them out completely. :)

-- 
 -D.                                          Sr. Information Adjuster
 dgc at uchicago.edu                Department of Information Adjustments
                        Ministry of Information, University of Chicago




More information about the Gnupg-devel mailing list