#### Archived

This topic is now archived and is closed to further replies.

# inline ( )

This topic is 5705 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

my c++ book didnt really say a lot abt inline functions, so i was wondering if they are really necessary..?

##### Share on other sites
For small functions like plotting pixels, inline functions make your program a lot quicker because they don''t have to bother with the stack. This is basically what an inline function does. If you have

inline void function1()
{
/* do function1 stuff here */
}

void main()
{
function1();
}

If I''m not mistaken, an inline function would turn it into this before it compiles..

void main()
{
/* do function1 stuff here */
}

They''re sometimes necessary for optimization, but as a beginner programmer you probably won''t find much of a use for them for some time.

On the subject of inline functions... What do you think would happen if you made an inline recursive function?

- f l u c k y p o o
- the geek inside

##### Share on other sites
They arnt realy nesicery at all;
but if you have some small functions that are called alot, they shuld be inline.

An inline function is when the compiler replaces the function call with its body:
inline void foo(){    int poo;    if(1)     beer();    bar();    return;}void main(){    foo();    return;}would be replaced withmain(){    int poo;    if(1)     beer();    bar();}

the INLINE keyword is inly used durin compile time;

An example of using an inline function would be like using abs(),rand() and other small functions.

Inline functions make the executable larger.

##### Share on other sites
uhh! i got a 500 http server error 8 times to post this (above) replay, EIGHT!
fuck!
fix the godamn software, its not THAT hard. grr.
anyway, yeh.
what i said

[ my engine ][ my game ][ my email ]
SPAM

##### Share on other sites
Also.. as I understand it, inlining is a request to the compiler, not a command. Which simply means the compiler can ignore the inline and compile like a normal function.

##### Share on other sites
quote:
Original post by Anonymous Poster
Also.. as I understand it, inlining is a request to the compiler, not a command. Which simply means the compiler can ignore the inline and compile like a normal function.

Yes, the compiler can ignore an inline directive under certain circumstancies:
-the function you want to inline is recursive
-the function accepts a variable number of parameters
-the cost/benefit calculation the compiler does results in a "don''t inline"
-maybe some other factors that do not spring to mind right now

AFAIK, MSVC++ has a keyword named _force_inline (or something like that) that would overrid the cost/benefit calculation

Forever trusting who we are
And nothing else matters
- Metallica

• ### Forum Statistics

• Total Topics
628715
• Total Posts
2984362

• 24
• 11
• 10
• 13
• 14