Archived

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

edwinnie

inline ( )

Recommended Posts

flucknugget    122
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 this post


Link to post
Share on other sites
aftermath    100
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 with
main()
{
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 this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest 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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites