-1

I have read somewhere that for functions not returning values, if a return statement exists inline expansion may not work.

Can anybody tell me the exact reason for this?

Niall
  • 30,036
  • 10
  • 99
  • 142
avinash pandey
  • 1,321
  • 2
  • 11
  • 15
  • Way too vague - please cite the source and the exact wording. – Paul R Sep 08 '14 at 10:51
  • Its written in Object Oriented Programming in c++ by Balaguruswamy.Wording is exact. – avinash pandey Sep 08 '14 at 10:54
  • @avinashpandey: Is that really the exact wording? The sentence is nonsensical as far as I can tell. Is the sentence talking about `void` functions? Does the book provide some kind of code example to illustrate this? Can you show a paragraph containing this sentence? – In silico Sep 08 '14 at 10:57
  • It never mentioned the return type of function but just said "Functions not returning any value".I guess it is void. – avinash pandey Sep 08 '14 at 10:59
  • Indian text books such as this (and others by Kanetkar) tend to be very out-of-date, inaccurate and of poor quality - even the latest edition (2013) of this particular book is still using Turbo C++ and `` etc. You would be better off getting more up-to-date books from reputable authors. – Paul R Sep 08 '14 at 11:25
  • @PaulR Thanks for the advice.Any suggestion for other books. – avinash pandey Sep 08 '14 at 13:12
  • @avinashpandey: there's a [useful list right here on Stack Overflow](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Paul R Sep 08 '14 at 13:29

2 Answers2

1

The inline keyword is more of a hint to the compiler than an explicit directive these days. There is no specific rule about not inlining functions with return statements. This would be pointless anyway because that is the only main difference between macros and inline functions.

Different compilers will generate different code for inline functions with just the inline keyword. MSC compiler has a __forceinline keyword which will force a function to be inline. Note that indiscriminate inlining will generate more code. These days performance overheads are rarely because of the overhead of a function jump. I would advise you to profile your code and not do any premature optimizations.

Niall
  • 30,036
  • 10
  • 99
  • 142
GlGuru
  • 756
  • 2
  • 10
  • 21
0

There is no such rule. However, inline is a request to the compiler to make this as macro if possible, for complex functions, inlining will be ignored and will be just like normal function.

Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69