5 ms·
Can anyone explain why this needs to be a macro? What does this get you over a plain function?
by tkahn6 15y ago
Can anyone explain why this needs to be a macro? What does this get you over a plain function?
- jedbrown 15y agoIt's intended to be used with lists with different payloads, all "inheriting" fields from a standard list structure (usually another macro expansion).
- saurik 15y agoThe "field" argument cannot be passed as an argument to a normal function in C. FWIW, you could pass it as an argument in C++ (which supports pointers to members), but in C++ there are numerous better ways of implementing this.
- tptacek 15y agoThe idiomatic way you'd express a generic tailq in C with functions is with void-stars, which cost 4-8 bytes and incur the costs of indirecting through another memory address and, probably, of allocating lots of fiddly little structs at random times. The macro version expresses the same generalized logic but embeds the link pointers in the structure you're queueing.
- tkahn6 15y agoThanks! Helpful as always.