I am trying to write a macro dbgassert similar to the standard assert. In addition to what assert does, I want to dbgassert
Your problem is the value of __VA_ARGS__ which is empty in the problem case. So, when the preprocessor expands realdbgassert(#EX, __FILE__, __LINE__, __VA_ARGS__), the result is an unfinished parameter list realdbgassert("1>2", "foo.c", 42, ). Note that the parameter list is not correctly terminated due to the empty expansion of __VA_ARGS__.
To fix this, you need to use some kind of trick. The best solution is, to tweak the circumstances so that __VA_ARGS__ includes the last unconditional argument, and pass that together with the optional ones at the end of the function call. This is best, because it's standard C.
The other fix that I know of, is a gcc extension to the language: See this gcc documentation page for more detailed info, but you can fix your macro by adding a double ## in front of __VA_ARGS__:
#define dbgassert(EX,...) \
(void)((EX) || (realdbgassert (#EX, __FILE__, __LINE__, ## __VA_ARGS__),0))
Ps:
The # is the stringification operator of the preprocessor: it turns the value of the macro parameter into a string literal, i. e. instead of pasting 1>2 it pastes "1>2".