티스토리 뷰

C++

Inline function in C++

seoca 2018. 11. 9. 10:02


Inline function 


In C++Inline function increases efficient performance to prevent function call overhead, if a small function has to be repeated. However, the inline function is not a command, which means compiler may ignore the request. Additionally, even though every function are changed to the inline function, it doesn't guarantee that it increases efficiency all the time because compiler decides to perform it or not. 




Example


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
inline int min(int x, int y) {
    return x > y ? y : x;
}
 
inline int MA(int m) {
    return m * m ;
}
 
int main()
{
    cout << min(68<< endl// 6
    cout << min(72<< endl// 2
    cout << MA(3<< endl;     // 9
 
    return 0;
}
 
cs