for a lot of quick tasks where one could employ a function f(x,y)
, in plain C, macros are used. I would like to ask specifically about these cases, that are solvable by a function call (i.e. macros used for inlining functions, not for code expansion of arbitrary code).
Typically C functions are not inlined since they might be linked to from other C files. However, static C functions are only visible from within the C file they are defined in. Therefore they can be inlined by compilers. I have heard that a lot of macros should be replaced by turning them into static functions, because this produces safer code.
Are there cases where this is a not good idea?
Again: Not asking about Code-Production macros with ## alike constructs that cannot at all be expressed as a function.
inline
ing functions just ensures it can be defined multiple times in the binary, the compiler can decide whether it will actually inline it to maybe save spaceinline
, this is not about C++.inline
in C, at least since C99. For a quick overview, see Wikipedia on inline functions.