I was curious. Macros vs. functions. Using macros would substitute the macro string possibly many times, so this would create much larger code than using a single function call? So would this make macros instead of using a function a disadvantage when it comes to memory usage because the memory usage for the program would be bigger w/macros?
Macros are evil. There is absolutely nothing a macro does better then a C++ function.
The only two exceptions are:
1) Include guards at the top of a header file.
2) Do automatically insert __LINE__, __FILE__ and __FUNCTION__ into your code. This is usually used for profiling.
Problems with macros (and this is only a partial list quickly put together):
- They don't show in the debugger (macros aren't symbols)
- Parameters can end up being evaluated multiple times
- They aren't type safe
- They duplicate code (i.e. they are always inlined)
- They pollute ALL namespaces.
- They are tricky to write.
Do yourself a favor, don't use them.