Inline functions, which weren't supported in C until the C99 standard (but your compiler definately supports them), are almost always preferable over macros. Macros may expand their arguments more than once, which can cause problems if you use an arithmetic operation on an argument. They're harder to debug, as the expanded code doesn't really exist at a place that the compiler can report problems to you unambiguously. Inline functions can catch type safety issues earlier because you have to explicitly declare the types of the arguments. Finally, multiline macros are a bad idea in general: They have a completely different syntax for "declaration" of a macro function because the entire body has to fit on one line, thus requiring the usage of \. This is error prone and harder to maintain than the normal function syntax.
Macros and inlines should be separated from each other, IMO. Macros are code generators, whereas inline functions are code. Macros allow you to do many things that inlines can not, like reduce the amount of work needed to create repetitive functions. So use the two concepts accordingly and there shouldn't be any confusion.
|