RFC: Avoiding #warning (C/C++ preprocessor extension)

Jarosław Staniek js at iidea.pl
Sun Oct 30 20:25:26 GMT 2005


Since KDE is becoming more portable, my proposal is to avoid using #warning 
C/C++ preprocessor's extension. Unlike #error, #warning is not a standard - 
several compilers in addition to gcc implement this. Msvc compiler does not.

See also:
http://www.csci.csusb.edu/dick/c++std/cd2/cpp.html
http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/war_directive.htm

Other issues:
- #warnings can be annoying to see during compilation if used too much.
- #warnings are not an substitute for communication and discussions about a
    given TODO or uncertainty
- #ifdef __GNUC__ is required to make code portable

To find a solution I would propose to:

1. Preferred way: Using doxygen @todo tag instead of #warning. Then warnings 
can be accessible:
1.1. Within Doxygen docs (Related Pages->Todo list), eg.
http://www.englishbreakfastnetwork.org/apidocs/apidox-kde-4.0/kdelibs-apidocs/kdecore/html/todo.html
1.2. By just grepping for @todo. This is no different to using #warnings 
because every #warning can quickly disappear from your screen during 
compilation, so you still need to find it in the code.

2. If somebody couldn't _really_ live without _several_ #warnings, please 
remember about adding #ifdef __GNUC__.

I know it's matter of taste, but for some people solution 2. looks dirty 
compared to solution 1.

-- 
regards / pozdrawiam,
  Jaroslaw Staniek / OpenOffice Polska
  Kexi Developer:
      http://www.kexi-project.org | http://koffice.org/kexi
  KDE3, KDE4 libraries for developing MS Windows applications:
      http://wiki.kde.org/tiki-index.php?page=KDElibs+for+win32




More information about the kde-core-devel mailing list