No. They are absolutely not a general replacement for functions.
Macros are capable of the fact that the code itself is not, especially creating and modifying tokens (code) before compilation.
In return, they lose all type safety and almost all syntactic sugar that may be available for actual code.
When you have to do something that cannot be done with code, or need conditional code (super-debugging stuff like memory tracing), macros come in handy. They also have some value in providing more concise or more readable ways of doing a certain thing (a common example is #define SUCCESS(x) (x >= 0) . However, for something that requires type safety, catch-exception, or consisting of often of the code used, t will have to mutate at compile time, they almost never work. Most of the code, which seems to be a macro, may be more safely expressed in real code, which is important for business logic.
The closest rule of thumb you can get is for something to happen or change at compile time. If so, consider the macro, otherwise just execute its code. Remember that templates are considered code and can do a lot of things that you might encounter under the influence of using a macro, but can be somewhat safer.
ssube source share