Bloomberg LP Interview Question
Software Engineer / Developersi think it is possible... abusing inline function will cause excessive code replacement -> bigger executable -> program too big that it cannot fit in the memory -> memory swap -> ultimately thrashing. slight chance this will happen but still possible...
answer is E....
because once I was asked a similar question in my interview at bloomberg...Though I couldn't answer the question on spot..I found it later....But, the question was no so straight forward...
How can it be E?
Doesn't inline just copy the code whenever the function is invoked. So if anything, compile time is quicker.
What might be slower is the act of looking up where the inline function is to do the code copy. -- But that's not really a compile-time dependency. It's more of a compiler implementation issue.
Not d. According to Herb Sutter, once and again chairman of the C++ standards committee, in his book 'Exceptional C++ Style', pg 192, he says: "The inline keyword is not required to have any semantic effect on a C++ program. It doesn't affect other parts of the standard language, in that writing inline on a function does not change how you use the function (for example, /you can still take the function's address/).. ". (Emph. mine.)
It is D. When making inline, code replacement will take place. When code replaced all the place, why to still keep the function in code segment. And when no function, how would one take address of the function.
Not E. --> It would increase dependency (e.g. what if function defined in separate compilation unit). But is that a disadvantage. After all we are more worried about the runtime of program even if it comes at some extra effort at compile time.
Regarding the comment mentioning that program might get slower. --> Swapping, Thrashing and all ....but its chances of making it slower as compared to the reduced time in saving function calls would be very very less
Answer: A
http: // msdn.microsoft. com/en-us/library/z8y1yy88%28v=VS.80%29.aspx
"Inline expansion alleviates the function-call overhead at the potential cost of larger code size."
its A....
wherever the compiler finds a call to an inline function, it writes a copy of the compiled function definition. so, execution time reduces but their is a trade-off with the memory. As memory requirement increases.
The reason C++ has inline functions and macros is to eliminate the overhead incurred by function calls. However, the tradeoff of this is the fact that the program size increases with both macros and inline functions.
Therefore the answer is A
It is E because: It increases compile time dependency because lets say the component A has an inline function which component B is using. If the function changes, since the function is inline(the function is sitting in the binary of B); B needs to be recompiled as well. If it was an ordinary function, it could have just been linked.
- sudarshan.fs August 27, 2010