That's “meta-programming” in C – sorry, I'm joking.
The #define __STRUCT_KFIFO_COMMON(datatype, recsize, ptrtype)
is a macro to define a union
.
It could be used for any kind of declaration, e.g.
typedef __STRUCT_KFIFO_COMMON(int, 64, int*) IntFiFo;
to define a union
type (alias) or
static __STRUCT_KFIFO_COMMON(int, 64, int*) intFiFo;
to declare a static
variable.
I must admit that I don't know anything about Linux Kernel programming – that's just what I read from this code (and how it would make sense).
Concerning
char (*rectype)[recsize];
rectype
is a pointer to a char[recsize]
.
Why the parentheses (()
)?: They are necessary because if missing this would be another (not intended) type:
char *rectype[recsize];
is an array of char*
with recsize
elements.
So, pointer to array vs. array of pointers, hence, the parentheses.
recsize
is one of the macro parameters. IMHO, it must be exclusively used with a constant integral value. Otherwise, it's probably an error. (VLA in a union? No, that doesn't work.)
Last a hint for how to decode confusing C types:
Try cdecl: C gibberish ⇆ English if in doubt. With recsize
it didn't work but replacing recsize
by a number it provided:
char (*rectype)[10];
declare rectype as pointer to array 10 of char
After having sent this answer, I googled c pointer to array site:stackoverflow.com out of curiosity and found
SO: C pointer to array/array of pointers disambiguation
as first hit which might be interesting for further reading.