Make "sys/queue.h" usable with C++

Hans Petter Selasky hps at bitfrost.no
Thu Jan 16 14:18:28 UTC 2014


Hi Paul-Henning,

On 01/16/14 14:46, Poul-Henning Kamp wrote:
> In message <52D7D302.3090403 at bitfrost.no>, Hans Petter Selasky writes:
>> Hi,
>>
>> I'm using "sys/queue.h" with some C++ programs. The only problem is that
>> you cannot make an ENTRY() using classes without getting some compiler
>> warnings, because all macros in "sys/queue.h" assume "struct".

>
> I came >< this close to removing the assumed struct many years ago
> when I orthogonalized sys/queue.h, but were persuaded by others that
> it was pointless and that nobody were ever going to use it with C++
> anyway, C++ being so much more evolved in such aspects :-)
>

Pointless ... hmm. After I've been programming some years in the kernel, 
I see no better way to make linked lists than using the macros inside 
"sys/queue.h". I love em. They are simple and straight forward. And 
gives you the flexibility of choosing the list type. Even GDB can be 
made to understand them. In my current code I simply:

#define struct
TAILQ_XXX()
#undef struct

And that works the few places I need it.

> Wouldn't
>
> 	#ifndef SYS_QUEUE_STRUCT
> 	#  define SYS_QUEUE_STRUCT struct
> 	#endif
>
> Make more sense ?

That's a valid possibility too. I would suggest stripping the SYS_ 
prefix because the queue file can reside other places too. Or make one 
macro for each list type?

#ifndef TAILQ_STRUCT
#define TAILQ_STRUCT struct
#endif

#ifndef LIST_STRUCT
#define LIST_STRUCT struct
#endif

and so on?

 >
 > That would allow C code to also make the struct explicit.
 >

Or for allowing typedef'ed structures.

Will you make a patch for it?

Another question: Who will distribute the queue.h updates to Linux and 
other OS'es. I see the Linux's sys/queue.h is already a bit behind ours.

--HPS


More information about the freebsd-hackers mailing list