If you want compatibility with compilers other than GCC then the current use of variadic macros is an issue:
#define EMIT(fun, arg...) (comp->emit_method_table->fun(comp->emit, ##arg))
C99 supports variadic macros but it would look like this:
#define EMIT(fun, ...) (comp->emit_method_table->fun(comp->emit, ##__VA_ARGS__))
Notice the removal of 'arg' from the ellipsis and the use of VA_ARGS.
Even with this change the code is still not portable across C99 compliant compilers. The use of '##' to remove the trailing comma when '...' is empty is a GCC specific implementation. In this case you could move to using two separate macros. Example:
#define EMIT(fun, ...) (comp->emit_method_table->fun(comp->emit, __VA_ARGS__))
#define EMIT_SINGLE(fun) (comp->emit_method_table->fun(comp->emit))
If you wanted to keep one macro then it would still be a pain because you would have to put 'fun' in with the other arguments.
#define EMIT(...) (comp->emit_method_table->__VA_ARGS__)
If you want compatibility with compilers other than GCC then the current use of variadic macros is an issue:
C99 supports variadic macros but it would look like this:
Notice the removal of 'arg' from the ellipsis and the use of VA_ARGS.
Even with this change the code is still not portable across C99 compliant compilers. The use of '##' to remove the trailing comma when '...' is empty is a GCC specific implementation. In this case you could move to using two separate macros. Example:
If you wanted to keep one macro then it would still be a pain because you would have to put 'fun' in with the other arguments.