Advertisement

inline ( )

Started by May 02, 2002 08:51 PM
4 comments, last by edwinnie 22 years, 6 months ago
my c++ book didnt really say a lot abt inline functions, so i was wondering if they are really necessary..?
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
- f l u c k y p o o
Advertisement
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.
Rate me up.
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
Rate me up.
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.
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
Forever trusting who we areAnd nothing else matters - Metallica

This topic is closed to new replies.

Advertisement