Macros dont allow empty arguments anymore - why?

 
#define func(arg1, arg2) Print(arg1); arg2;

func("Hello", ExpertRemove()) // fine
func("Hello",) // Warning


Makes no sense for me. There are many cases, when I explicitly do not want to have the second argument, but I also dont wanna mess up my code with even more macros with different names. On top, this works, but is actually the same:


#define func(arg1, arg2) Print(arg1); arg2;
#define _ 

func("Hello", ExpertRemove()) // fine
func("Hello", _) // fine

 

Why "anymore"?

AFAIK, MQL5 never supported variadic macros.

Why not to use functions?
 

Its since the last update. Before there was never a warning. 

Why not functions? Cuz they don't work for every case.
Example: I use this macro to define class members. One line, defines function name, datatype, varname, the code to be executed when set, code to be executed when get. It keeps my code (in my opinion) easier to understand at a glance. 

Same without macro:


The macro is:

// Property w/ member var (read/write)
#define IMPLEMENT_MEMBER_SET_GET(function_name,datatype,member_var,command_onset,command_onget) protected: datatype member_var; public: void function_name(datatype value) { if (member_var==value) return; member_var=value; { command_onset; } } public: datatype function_name(void) { { command_onget; } return member_var; } 
#define _set(code) {code;}
#define _get(code) {code;}
#define _


I also have macros for ForEach functionality, and many other stuff. 

 

Ok, so the question is not about skipping optional argument as a whole (which is not supported unfortunately), but about newly emerged warning about empty space after the coma.

Well, I think the warning is useful. Your workround with empty _ definition is much better than the hanging coma, imho, because it's clearly declares your intention, whereas the omission can be (and looks like) accidental.

PS. One little note about macros. Despite the fact that macros are indespensible with codegeneration (as in your case), it's very hard to debug such codes. Which is why I prefer to refactor such codes (whenever possible) into classes/templates. For example, you could have a template of SmartValue(T) with getter/setter and even optional event callback for intercepting/broadcasting changes, if it will be needed in future.

 
Stanislav Korotky #:

Ok, so the question is not about skipping optional argument as a whole (which is not supported unfortunately), but about newly emerged warning about empty space after the coma.

Well, I think the warning is useful. Your workround with empty _ definition is much better than the hanging coma, imho, because it's clearly declares your intention, whereas the omission can be (and looks like) accidental.

PS. One little note about macros. Despite the fact that macros are indespensible with codegeneration (as in your case), it's very hard to debug such codes. Which is why I prefer to refactor such codes (whenever possible) into classes/templates. For example, you could have a template of SmartValue(T) with getter/setter and even optional event callback for intercepting/broadcasting changes, if it will be needed in future.

Yeah you are right. Actually I like the '_' definition, since its very close to _ in C# which means "suppress/empty". As long as it stays like that, I am fine with it. I am only concerned, that this also could become a problem in the future. 

Regarding debugging - you are also right. Of course I wouldn't use for more complex code, but stuff like such, there is actually nothing to debug. Nonetheless, its all a matter or personal taste.