Thread: inline void

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    Smile inline void

    is there any difference in inline void and void?
    because i have noticed that
    Code:
    #include <iostream>
    using namespace std;
    inline void hello()
    {
        cout<<"hello world"<<endl;
    }
    int main()
    {
        hello();
        cin.get();
    }
    will do the same if i leave out inline
    Code:
    #include <iostream>
    using namespace std;
    void hello()
    {
        cout<<"hello world"<<endl;
    }
    int main()
    {
        hello();
        cin.get();
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    why don't you look up 'inline'
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    21
    Yes, they both are different.
    inline void hello() will result in the function call being replaced by the definition during compile time. Hence there will be no overhead involved in pushing the contents to and from the stack that happens in the normal function call.
    PS: the functions defined within the class definition is treated as inline. EG:
    <<< UNTAGGED CODE DELETED >>>
    Inline functions will reduce the function time if the function is not complicated.
    Last edited by Salem; 10-21-2004 at 12:15 PM. Reason: deleting untagged code

  4. #4
    Banned
    Join Date
    Oct 2004
    Posts
    250
    i have it doesnt say if it makes a differnce to the program
    and does anyone know how to fix this program
    Code:
    #include <iostream>
    #define IsVowel('a'||'i'||'o'||'u')
    using namespace std;
    int main()
    {
        char letter [256];
        cout<<"enter a letter"<<endl;
        cin.getline(letter, 256);
        if(strcmp(letter, 'IsVowel')==0)
        {
            cout<<"its a vowel"<<endl;
        }
        else cout<<"its not a vowel"<<endl;
        cin.get();
    }

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    21
    You can try this out. It works.

    <<< UNTAGGED CODE DELETED >>>
    Last edited by Salem; 10-21-2004 at 12:16 PM. Reason: <<< UNTAGGED CODE DELETED >>>

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    21
    Inline doesn't make any difference to your program except that it reduces the exceution( run) time.

  7. #7
    Banned
    Join Date
    Oct 2004
    Posts
    250
    ah ok and
    Code:
    if ( strchr( ISVOWEL, x ) )
    compares ISVOWEL with x?

  8. #8
    Registered User
    Join Date
    Oct 2004
    Posts
    21
    It doesn't compare. It returns pointer to first occurrence of x in ISVOWEL string.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  3. i cannot see the mouse arrow
    By peachchentao in forum C Programming
    Replies: 6
    Last Post: 12-10-2006, 04:14 AM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM