#ifdef vs #if for feature checks

Lubos Lunak l.lunak at suse.cz
Fri Mar 15 08:58:36 PDT 2013


 I'd like to propose that we convert our

#ifdef HAVE_FOO



 The reason for this is that the sooner cannot tell a difference between the 
FOO feature not being there and any mistake (such as typo in name or #include 
<config_xxx.h> missing). As a practical example, I found out few days back 
that there was some code in the KDE vclplug that was never enabled, because I 
when writing it back then I added the necessary dmake stuff for the #define, 
but later vcl was converted to gbuild using gbuild patches from OOo, which 
didn't have it, so the feature was silently dropped.

 If we use the #if HAVE_FOO form, then with -Wundef any such mistake will be 
easily detected. It will also require adding #ifndef HAVE_FOO #define 
HAVE_FOO 0 #endif to config_xxx.h files, and the actual conversion, but that 
can be an easy hack.

 The problem with this change is that there still may be some cases where 
#ifdef is used, either because some system #defines work that way (so those 
would be valid but different), or people would still use #ifdef out of habbit 
or from AOO, which would then be broken, since the macro would be always 
defined. This however still should be possible to check mechanically, while I 
do not see a way to prevent the problem above.

 Opinions on this?

 Lubos Lunak
 l.lunak at suse.cz

More information about the LibreOffice mailing list