I think the question you're asking is confusing so let me restate it You want to use variadic templates to write a function that simulates inlining a variadic function It cannot be done va_args is often implemented as a void* to the first parameter on the stack (note variadic functions are required to have at least one non-variadic argument for exactly this reason) You would need to manipulate the call stack to get the parameters in the right place. Now it might be the case that the variadic template function's arguments are on the stack in the same location as va_args would want them but that would require the template function to not be inlined I strongly suspect the reason always inlining variadic function is unimplemented is because of the implementation of va_args assume standard stack layout. For the compiler to inline that function it would need to allocate stack space and copy the parameters in place.
The only thing it would save is actual jmp and ret instructions It could be done, but half of the benefits of inlining evaporate. Further the compiler will have to hoist the parameter passing code (compiler code that is) to a more general location for use with regular function calls as forced inline of variadic functions. In other words it complicates the control flow significantly for small to no benefit.
I think the question you're asking is confusing so let me restate it. You want to use variadic templates to write a function that simulates inlining a variadic function. It cannot be done.
Va_args is often implemented as a void* to the first parameter on the stack (note variadic functions are required to have at least one non-variadic argument for exactly this reason). You would need to manipulate the call stack to get the parameters in the right place. Now it might be the case that the variadic template function's arguments are on the stack in the same location as va_args would want them but that would require the template function to not be inlined.
I strongly suspect the reason always inlining variadic function is unimplemented is because of the implementation of va_args assume standard stack layout. For the compiler to inline that function it would need to allocate stack space and copy the parameters in place. The only thing it would save is actual jmp and ret instructions.It could be done, but half of the benefits of inlining evaporate.
Further the compiler will have to hoist the parameter passing code (compiler code that is) to a more general location for use with regular function calls as forced inline of variadic functions. In other words it complicates the control flow significantly for small to no benefit.
You could implement your own sprintf_l int __noninlined_sprintf_l(char *__s, locale_t __l, const char *__format, ...) { va_list __va; va_start(__va, __format); int __res = vsprintf_l(__s, __l, __format, __va); va_end(__va); return __res; } And call that instead template int __sprintf_l(char *__s, locale_t __l, const char *__format, Args... args) { int __res = __noninlined_sprintf_l(__s, __l, __format, args...); return __res; }.
This is what I ended up doing, but due to what deft_code says above, didn't work completely... The code was removed for my use-case, so the problematic code became unused, solving the direct problem. – rubenvb Oct 3 at 16:07.
Template int variadic(char* s, locale_t locale, const char* format, T&&... t) { return __sprintf_l(s, locale, format, std::forward(t)...); } Then calling variadic(s, l, "%d %s", 42, "") would result in a call to __sprintf_l(s, l, "%d %s", 42, ".
Although I like the code, this is not what the question asked. I'm not going to -1 though as the question is poorly worded. – deft_code Sep 27 at 19:02.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.