TITLE: inlining of variadic functions (Newsgroups: comp.std.c++, 27 Sept 97) BOSSI: Paul Bossi[SMTP:bossi@primenet.com] > ... if I declare an inline function with >variable arguments it is *never* inlined. Also in both cases, if I >simply remove the ellipsis arg the function always is inlined. > >The fact that this behavior happens on two widely used and relatively >conformant C++ compilers leads me to believe that there's something in >the standard that either condones or forces it. CLAMAGE: stephen.clamage@eng.sun.com (Steve Clamage) Nothing in the standard suggests that any particular kind of function should not be inlined. But practical matters of implementation sometimes mean that some functions are just not going to be inlined. A variadic function needs to use the facilities to get at or pass along its arguments. (And it doesn't make sense to base compiler optimizations on pathological cases like variadic functions that ignore their arguments.) Those facilities in turn depend on details of the stack frame, and depend on finding particular arguments at particular offsets. If the function is inlined, it may not be possible to ensure those arguments appear at the right place, since in general the inline function body will be mixed with the calling expression. Thus, in order to inline a variadic function, you would need to turn off optimizations that would result in mixing the inlined function body with the expression surrounding the call, and take steps to force the inline function's arguments onto the stack in a way that simulates a function call, possibly also needing to create an actual stack frame. It seems very unlikely that you would get any net benefit compared to not inlining the function, but it would greatly complicate the compiler. On some particular platform it might be the case that inlining a variadic function imposes no special considerations. In that case, they would be more likely to be inlined. But also consider that a variadic function typically contains a loop and sometimes also a switch statement, and it is common for compilers to refuse to inline a function containing either of those constructs.