Seeing this question , I asked myself the question why the approach (example of a toy):
#define foo(x) bar[x] = 0
functions will always be preferable:
void foo(unsigned x){ bar[x] = 0; }
Before the question related above, I saw this before, in the PolarSSL library, where I assumed that it was some kind of optimization, and tried not to think too much about it.
I assume that using the preprocessor macro replaces the “call” with the “body of nothingness” wherever it exists; while a function voidmay be optimized by the compiler or may not be optimized, and therefore may result in a large fork for a small and simple operation or two.
Are there any other benefits?
When is it preferable to use the macro method, and when is it best to trust the compiler?
source
share