Saturday, May 22, 2010

What are the disadvantages to declaring a function inline in c?

I know that you generally declare a function inline when it is really short because it eliminates the whole control switching thing, but what are the disadvantages of it? Like why wouldn't you declare larger functions inline?

What are the disadvantages to declaring a function inline in c?
thats because when larger functions that are used many times is declared inline its gonna increase the size of the program during compilation..... and if these large functions are used many times like in a for or while loop then there will be no use for the inline declaration as the compiler will not know when the looping will end..... and so inline is used mostly when the function is small and is executed for a finite number of times in the program....
Reply:The disadvantage is that the code for the function will be inserted into the compiled program each time the function is called. For a large function, the extra space overhead isn't worth the speed gained by eliminating a function call.


No comments:

Post a Comment