William Ahern <william@wilbur .25thandclement .comwrote:
Christof Warlich <cwarlich@alcat el-lucent.dewrote:
Hi,
is there any way to access individual elements in the body
of a variadic macro? I only found __VA_ARGS__, which always
expands to the complete list.
of a variadic macro? I only found __VA_ARGS__, which always
expands to the complete list.
So, using Laurent's solution you can do lots of interesting things. For
instance, you can overload functions or macros:
instance, you can overload functions or macros:
#define foreach2(p, a) \
for (typeof(&(a)[0]) p = (a); p - (a) < lengthof(a); p++)
for (typeof(&(a)[0]) p = (a); p - (a) < lengthof(a); p++)
#define foreach3(p, a, n) \
for (typeof(&(a)[0]) p = (a); p - (a) < (n); p++)
for (typeof(&(a)[0]) p = (a); p - (a) < (n); p++)
illustrative of C99 standard compliant overloading using number of arguments
as the differentiator.
Leave a comment: