Macro vs. Static functions in Header

Posted by wirrbel on Programmers See other posts from Programmers or by wirrbel
Published on 2013-10-18T08:21:04Z Indexed on 2013/10/18 10:14 UTC
Read the original article Hit count: 167

Filed under:

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.

© Programmers or respective owner

Related posts about c