Skip to content

VS inline VS macro

Inline functions vs Preprocessor macros

In C++, what’s the difference between an inline function and a macro?

marco的优势

在阅读offsetof这篇文章的时候,其中提及了这样一段话:

C's offsetof() macro is an ANSI C library feature found in stddef.h. It evaluates to the offset (in bytes) of a given member within a struct or union type, an expression of type size_t. The offsetof() macro takes two parameters, the first being a structure name, and the second being the name of a member within the structure. It cannot be described as a C prototype.[1]

即如果使用函数的话,offsetof cannot be described as a C prototype,所以才使用marco;