Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6618937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:54:08+00:00 2026-05-25T20:54:08+00:00

In an attempt to bypass GCC’s unimplemented always-inlining variadic functions in libc++, I thought

  • 0

In an attempt to bypass GCC’s unimplemented always-inlining variadic functions in libc++, I thought I could maybe wrap the variadic functions (like snprintf, more precisely, the *_l variant) in a variadic template to achieve a similar effect. An instantiation would fill in the variadic function’s varargs, allowing the function to be nicely inlined. The problem is, I don’t know the first thing about writing variadic templates, and I certainly don’t know how to turn the template arguments into seperate arguments.

The code I’m looking to replace is of the form:

int __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;
}

I’d like to replace is with something of the form:

template<typename... Args>
int __sprintf_l(char *__s, locale_t __l, const char *__format, Args... args) {
  int __res = vsprintf_l(__s, __l, __format, args...);
  return __res;
}

This is not working, due to the expanded args... which cannot be converted to type to va_list {aka char*}. If there is no way, I’ll have to trust Howard and implement one-, and two-argument always-inline templates, which would effectively double the amount of needed code.

EDIT: perhaps a way to convert the std::tuple that args is into a va_list would work here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:54:08+00:00Added an answer on May 25, 2026 at 8:54 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an attempt to rephrase a question I asked earlier. I'd like to
In an attempt to wrap some unmanaged code in a managed .dll I'm trying
Why does this attempt at creating a list of curried functions not work? def
Is there any attempt to re-make something like Vimeo's couch mode http://vimeo.com/couchmode in jQuery?
I'd like to note first that this is an education attempt on my own
My first attempt and JSON desrialization and I'm stuck, just wondering if you could
First attempt to use this cool site - after searching for 2 hours: So
If I attempt to connect to Mac OS X 10.5 Leopard's built in vnc
In an attempt to add some parameter validation and correct usage semantics to our
When you attempt to declare an unsigned variable in C#.NET with a value outside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.