I remember having read somewhere that VisualC++ does not inline a funtion as soon as a loop is in there or an if statement.
But i cant find the documentation about that anymore, anybody knows these rules or where to find them?
This is a discussion on inline VisualC++ within the Windows Programming forums, part of the Platform Specific Boards category; I remember having read somewhere that VisualC++ does not inline a funtion as soon as a loop is in there ...
I remember having read somewhere that VisualC++ does not inline a funtion as soon as a loop is in there or an if statement.
But i cant find the documentation about that anymore, anybody knows these rules or where to find them?
That's not true.
It inlines this just fine:
Code:#include <iostream> void test() { for (int i = 0; i < 10; i++) std::cout << "Hello World!\n"; } int main () { test(); }
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
No doubt the decision as to whether to inline or not depends on many factors.
To mention a couple which Elysia's example does not show:
- a loop where the number of iterations is not known at compile time might not be inlined.
- a loop body consisting of many statements might not be inlined.
Inlining works best when the cost of calling the function becomes significant in the total amount of work done. So a simple function performing an assignment would be ideal. Inlining an entire sort function is unlikely to make much of a difference (except to bloat the code).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
I don't think it's a simple rule as to whether to inline or not. The following is still inlined:
Compilers are probably smarter than this.Code:#include <iostream> void test(int n) { for (int i = 0; i < n; i++) std::cout << "Hello World!\n"; } int main () { int n; std::cout << "Enter num loops: "; std::cin >> n; test(n); }
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
it seems the documentation I was looking for is outdated now and that VisualC++ has cost/benefit analyzing code now that decides if something is inlined.