inline VisualC++

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 ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    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.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    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, 06: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, 12:26 AM
  5. inline??
    By bman1176 in forum C++ Programming
    Replies: 2
    Last Post: 06-25-2002, 05:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21