The Inline Function Format is as follows:
Inline int FAC (int I) {return I * I ;}
Inline functions, like common functions, require reference type checks, but it is more efficient to execute inline functions than to execute common functions, because calls to inline functions do not need to be interrupted, inline functions are embedded into the target during compilation.CodeMedium.
Applicable scenarios:
1) the code is short and does not include loops.
2) need to be called repeatedly
The macro format is as follows (Note: There is no semicolon ):
# Define min (A, B) (a)> (B )? (B): (a) # define FAC (I) (I) * (I ))
Macros are only simple replacement of characters and are completed during preprocessing. macros are important in C, but are rarely used in C ++.
The differences between the two are summarized below:
1. The macro character replacement is completed during preprocessing (executed by the Preprocessor), and the inline function is embedded into the target code (executed by the compiler) during compilation)
2. inline functions are safer, because inline functions require parameter type check, while macros only replace simple characters.
Refer:
1 .《ProgramMember interview book (second edition): 6.4 inline functions and macro definitions of e-Industry Press
2. Baidu Encyclopedia: preprocessing