Thread: inline VisualC++

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    inline VisualC++

    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?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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();
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't think it's a simple rule as to whether to inline or not. The following is still inlined:
    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);
    }
    Compilers are probably smarter than this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inline assembly and compiler optimizations?
    By TmX in forum C Programming
    Replies: 6
    Last Post: 03-04-2010, 07:41 PM
  2. When to inline your *tors
    By Angus in forum C++ Programming
    Replies: 43
    Last Post: 10-29-2008, 03:38 PM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  5. inline??
    By bman1176 in forum C++ Programming
    Replies: 2
    Last Post: 06-25-2002, 05:31 PM