Since the root problem seems to be the assumption that "type" is a struct, why not simply omit the "struct" keyword under C++? For example:
#ifdef __cplusplus #define __sys_queue_struct #else #define __sys_queue_struct struct #endif
Of course, change most instances of "struct" to __sys_queue_struct, and #undef this at the end of queue.h. I'm running buildworld with this patch now.
As it turns out, my suggestion would need extra work. In some places, "type" is not declared enough to appease C++. For example, ktr_request in sys/proc.h, callout in sys/_callout.h, and aiocblist in sys/socketvar.h. These are trivially fixed with forward declarations, or by reordering the declarations. However, out-of-tree consumers might require changes. Thoughts?
Some better explanation is in order. I've used the sys/queue.h macros in the past in C++ with no issues. The extra stuff you've done seems unnecessary. What's the problem that having the _CLASS stuff solves, and why do you need the non-standard __typeof?
Why is this needed? Class and struct are the same thing in C++, with the definition controlling whether the members are public by default or not.
__typeof doesn't work on older compilers. Bde will give you 10k words on this if you commit it.
HPS: Yes, my suggestion works with 'extern "C"'.
Note that 'extern "C"' does not mean "this is C code". If you're compiling with a C++ compiler, it's C++ code. The 'extern "C"' declaration simply affects the linkage and calling convention. That is, the types of the parameters are not included in the symbol, and it doesn't get mangled.
You will also need the three other header file changes from D2767.
In my experience, it is good etiquette to test the build and basic functionality before asking for a code review. Asking for a review prematurely might be wasting your reviewers' time. Also, since you're going to put your reviewers' names on the commit, they deserve a chance to review the final code, including all the trivial build fixes.
I would strongly recommend a ports exprun, since we found three places that needed a fix in the base system alone.
Almost every occurrence of "struct type" needs to be changed to use QUEUE_TYPEOF. See D2767.
to avoid namespace pollution.
This sentence is really two different sentences. Removing the comma after "class" helps, but it is still too complicated. Better to split it:
In the macro definitions,