c++ - Mixing inline and macro functions -
i've decided try something. know macros evil , should avoided wanted see what's going happen if such thing.
#include <iostream> using namespace std; inline void add(int x, int y) { cout << "inline: " << x + y << endl; } #define add(x,y) ( cout << "macro: " << x + y << endl ) int main() { add(3,5); }
it outputs:
macro: 8
if comment out #define
line inline starts working, , output turns inline: 8
.
my question is, why compiler decides use macro function instead of inline. thank you!
i'm using
linux mint 18.2
,g++ 5.4.0
, no parametersg++ -g t2.cpp -o t2
.
macro substitution performed via pre-processor before compilation. compiler never sees add(3,5)
- sees macro expansion.
Comments
Post a Comment