I’m trying to move a project from an old linux platform to a kubunutu 9.04. Now I get this error when compiling with gcc 4.3.3:
/usr/src/linux-headers-2.6.28-11-generic/include/linux/cpumask.h:600:37: error: 'and' may not appear in macro parameter list
If I understand the message right, it is not allowed to use ‘and’ as a macro parameter, since it is a ‘reserved command’. Two questions about that:
- How is this possible? I cannot imagine that there is such a mistake in the linux header files… Did I do something wrong before? I tried an #undef and but this won’t help.
- How do I fix this error? It cannot be true that I have to change the linux header files, can it?
Thanks for help.
I believe the problem is that
andis a keyword in C++ but not C (they use&&).The kernel guys sometimes macros as an alternative to inline functions. Sometimes, however, they need macros because what they want to do has to be done in the scope of the calling function, and defining a function to do that won’t work (for instance a macro to find out the name of the current function).
Assuming the macros in question are really fake inlined functions, it would be possible to write your own .c file full of nothing but functions calling these macros, compile it, and refer to those functions via an
extern 'C'header. You would get the same behavior, but slightly worse performance (which is unlikely to be a problem).If the macros actually have to be macros, then your best bet is to hand edit them to be C++ compliant.