ID:2380269
 
Applies to:
Status: Open

Issue hasn't been assigned a status value.
It would be nice to be able to use zero-argument macros, so that they could appear more similar to procs:

#define perform_action() call("foo", "perform_action")()


Currently the compiler rejects such macros with an error ("empty macro argument"); a typical C preprocessor has no problem with them. I would expect that they be callable like "perform_action()" but NOT like "perform_action".
Purely for fun, I decided to try and create a workaround that doesn't require backend changes. I ended up with this evil contraption:

;try;null;catch


You would use it like so, in your example:

/world/proc/returns_two()
return 2
#define perform_action call(world, "returns_two")(); try;null;catch
/proc/main()
world.log << perform_action
world.log << perform_action()


Makes your macro usable both with and without parentheses.
I feel bad.

Edit:
This one doesn't even throw a warning:
#define perform_action call(world, "returns_two")(); try;.;catch
You can use a variadic macro which accepts a variable number of arguments, including zero:
/world/proc/returns_two()
return 2
#define perform_action(blah...) call(world, "returns_two")()
/proc/main()
world.log << perform_action()
world.log << perform_action(also pretty much everything in here is ignored)
The other two workarounds I am looking at are:
#define perform_action call(world, "returns_two")

and:
/proc/perform_action() return world.returns_two()


Unfortunately neither will complain at compile-time when the wrong number of arguments is provided, which is one of the side-benefits of using macros for this.