1

Possible Duplicate:
Benefits of inline functions in C++?

My teacher explained that having a inline function instead of a standard function would make your code run faster because it insert the complete body of the function in every place that the function is called, rather than generating code to call the function in the one place it is defined. Doesnt that make the code run slower??

Why dont people make every function inline since it is faster compared to a standard function??

Community
  • 1
  • 1
Computernerd
  • 7,378
  • 18
  • 66
  • 95
  • 1
    Inline functions take up more memory because the code for the function is duplicated for every place it is called. – Lee Meador Dec 28 '12 at 16:45
  • @LeeMeador does that mean inline function is slower compared to standard function? – Computernerd Dec 28 '12 at 16:47
  • 1
    "Is slower" "Is faster" are naive and meaningless metrics without qualification. "Slower" under which circumstances, at which time, and by what measure? Context is crucial. – Lightness Races in Orbit Dec 28 '12 at 16:48
  • 1
    There is confusion in this area because C++ has "inline" functions, like `inline int foo();`, but this is different from *inlining*, where the compiler optimizes your code by removing function calls, as your teacher says. Using C++'s inline keyword used to affect this optimization, but these days it no longer does and you get no guarantees about inlining behavior from the language alone. Yes, inlning everything can make your code run slower, which is why it's best to let your compiler do its job. – GManNickG Dec 28 '12 at 16:49

0 Answers0