I'm wondering if it's possible to "nest" variadic macro invocations. I'm only truly concerned with GCC and Clang. My macro definition looks like this:
/**
* @brief Invoke an instance method.
*/
#define $(obj, method, ...) \
({ \
typeof(obj) _obj = obj; \
_obj->interface->method(_obj, ## __VA_ARGS__); \
})
I use this to conveniently call "instance methods" in my OO framework (https://github.com/jdolan/objectively):
$(array, addObject, obj);
Works boss. Unfortunately, I haven't yet figured out a way to allow nesting of these calls, which would be very useful in some situations; e.g.:
/**
* @see MutableSetInterface::addObjectsFromArray(MutableSet *, const Array *)
*/
static void addObjectsFromArray(MutableSet *self, const Array *array) {
if (array) {
for (size_t i = 0; i < array->count; i++) {
$(self, addObject, $(array, objectAtIndex, i));
}
}
}
The nested variadic macro invocation above fails to compile because the inner invocation is never expanded. Is it possible to fix this, or have I already abused the preprocessor to its limits? :)