[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    fixing crappy X headers
From:       Lubos Lunak <l.lunak () sh ! cvut ! cz>
Date:       2001-05-19 11:53:53
[Download RAW message or body]


 Hello,

 as we all know, X11 headers #define some identifiers like None, Unsorted, 
etc. that usually break compilation and need to be fixed by #undef-ing, 
changing compilation file order and other messy techniques ( KWin is a nice 
example of this, IIRC there's some A->B->C->A dependency solved by a bunch of 
#define's and #undef's ... I also wonder when and who will remove the #define 
select madness ... oh well ).
 Anyway, I've come with a simple solution how to avoid this. Everytime you 
get a parse error because of this, simply #include <fixx11h.h> and all those 
identifiers will be put in a namespace called X, so they still will be 
available and people willing to use them can either use X::None or using 
namespace X; .
 The trick is quite simple, it looks like this :

namespace X
{
// --->
#ifdef None
#ifndef FIXX11H_None
#define FIXX11H_None
const int XNone = None;
#undef None
const int None = XNone;
#endif
#undef None
#endif
// <---
};

 Ok, looks probably a bit complicated, but it simply does #define None -> 
X::None . To use it, just simply include the file after including X11 headers 
or before the place where the problem occurs, it may be included repeatedly 
and the compile time increase is unnoticeable.
 I've already modified my local kdelibs ( it was only a few changes like 
XKeyPress -> X::KeyPress etc. ) and I'm now compiling kdebase. I'll commit 
after the freeze is over. The macros that get converted are : None, Bool, 
Unsorted, KeyPress, KeyRelease, Above, Below, FocusIn, FocusOut . Did I miss 
some important ?

 Oh, and BTW, Xlib is one of the reasons I use NULL, None, etc. Did you know 
that some Xlib functions return 0 for success, while other return 0 for 
failure , depending on whether this 0 means None, False or Success ? Things 
may get a bit interesting for people just using 0 :).

 Lubos Lunak
--
 l.lunak@email.cz ; l.lunak@kde.org
 http://dforce.sh.cvut.cz/~seli

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic