macro returning length of arguments in C

Posted by anon on Stack Overflow See other posts from Stack Overflow or by anon
Published on 2010-02-22T01:10:57Z Indexed on 2010/04/09 1:33 UTC
Read the original article Hit count: 359

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c

    Related posts about macro