macro returning length of arguments in C
- by anon
Is it possible to write a C macro that returns the length of its arguments?
I want something that does:
foo(1) -> 1
foo(cat, dog) -> 2
foo(red, green, blue) -> 3
Even better if this macro can be defined in such a way that it works with ## so that
foo(1) -> bar1(1)
foo(cat, dog) -> bar2(cat, dog)
foo(red, green, blue) -> car3(red, green, blue)
Thanks!
EDIT: I really want a macro, not a function. Suggestions to use functions will be downvoted.