Sometimes yes, sometimes no. When large functions are inlined, the executable generally grows larger. However when small functions are inlined, the executable can actually become smaller, since the amount of executable code needed to call a function, including pushing all the registers and parameters, can be larger than the amount of code that would have been generated had the call been inlined. Consider the following example. With optimization turned on, the size of the generated code was 33% smaller when the member functions were inlined compared to when they were not inlined. class Stack { public: Stack() throw(); void push(int elem) throw(); int pop() throw(); int top() const throw(); bool full() const throw(); bool empty() const throw(); protected: enum { dataMax_ = 10 }; unsigned len_; int data_[dataMax_]; }; inline Stack::Stack() throw() : len_(0) { } inline void Stack::push(int elem) throw() { data_[len_++] = elem; } inline int Stack::pop() throw() { return data_[--len_]; } inline int Stack::top() const throw() { return data_[len_-1]; } inline bool Stack::full() const throw() { return len_ == dataMax_; } inline bool Stack::empty() const throw() { return len_ == 0; } int main() { Stack s; s.push(0); s.push(1); s.push(2); s.push(3); s.push(4); s.push(5); s.push(6); s.push(7); s.push(8); s.push(9); s.pop(); s.pop(); s.pop(); s.pop(); s.pop(); s.pop(); s.pop(); s.pop(); s.pop(); s.pop(); } |