tags:

views:

417

answers:

3

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:

  1. 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.
  2. How do I fix this error? It cannot be true that I have to change the linux header files, can it?

Thanks for help.

+1  A: 

The linux headers are C headers, not C++.

anon
Perhaps extern "C" will fix this?
Dan Olson
No, it won' - that just specifies the linkage, not the language syntax.
anon
Of course, how stupid of me. The solution is to not include the file.
Dan Olson
A: 

It would help if you also showed the line in question. Perhaps it's all down to context, if you do something crazy before including the header, the compiler might be confused and generate a non-obvious error message.

There are cases when "and" is indeed a reserved word, and if it's C++-only the kernel developers won't care too much since the kernel is focused on C.

unwind
+1  A: 

I believe the problem is that and is 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.

Max Lybbert