Macro
Good things: is easier for the programmer
Bad Things: harder on the computer, unless the macro is only used 1 time, and if it’s only used one time, why did you bother making a macro
Function
Good things: is easer on the programmer,
keeps the compiled code size small
easier on the processor, will not create as many page faults, doesn’t need as much memory, tends to stay in all the caches far more
This is not to say a macro shouldn’t be used, it definitely has it’s place in coding. For instance, if we know that we are going to be doing a lot of loops, and the loops are are taking the basic same form of input, i.e.
Start index, End Index, etc. Then why not create a macro, to do that, for we are going to have to do that anyway, so it’s easier on the programmer.
When not to do it, when the macro is going to be humongous, and used all over the place. Because the compiler is going to “inline” (i.e. replace that one blueprint nodes, with all the nodes that are in the macro) the code. This can lead to a lot of code bloat, because the compiler is not going to see it as a macro. The first scan over the tokens/nodes, is going to expand each macro, making it far easier on the lexical analyzer, etc to deal with it. In this fashion, whether the code has macro’s or not, it all looks the same to the lexical analyzer, or tokenizer, just a stream of statements/blue print nodes.
So if you will, a function is actually a part of the processor, in that there are instructions for dealing with functions. A macro is a part of the “editor” in that it’s a convenience. And the core compiler, and certainly the processor, has no idea what the hell a macro is.