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

  • Home
  • SEARCH
  • 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 7834433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:09:02+00:00 2026-06-02T13:09:02+00:00

I have a function : static int myprintf(const char* fmt, …) I want to

  • 0

I have a function :

static int myprintf(const char* fmt, ...)

I want to know the size in bytes of all myprintf arguments,if they were printed to buffer.
I need allocate an array dynamically to which I can print the the arguments (using sprinf or _vsprinf)
For example in 32bit OS,for myprintf(“%d %c”,10,’a’);
the size of myprintf arguments is 5.

I tried to implement it like:

va_list ap;

va_start(ap, fmt);

myArgSize(ap);

Can someone advise how to implement myArgSize.

I was told to try something like this

char c;
int len = ::_vsnprintf(&c, 1, fmt, ap);

It doesn`t work since more than one byte is written.
But probaly there is some workaround.

Thanks

  • 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-06-02T13:09:03+00:00Added an answer on June 2, 2026 at 1:09 pm

    Even though much of your question is about the size of the arguments passed to your triadic function, it seems to me that you’re actually interested in how big the output buffer needs to be. Try something like the following:

    va_list ap;
    
    va_start(ap, fmt);
    
    int len = ::vsnprintf( NULL, 0, fmt, ap);
    if (len < 0) abort();
    
    char* buffer = (char*) malloc( len + 1);
    if (!buffer) abort();
    
    ::vsnprintf( buffer, len+1, fmt, ap);
    
    va_end();
    

    However, if your platform doesn’t have a C99 standard compliant vsnprintf() (for example, MSVC) then you’ll have to make some adjustments. For MSVC You could try passing in a buffer sized with a guess (maybe strlen(fmt)+1 + (10 * number_of_percent_signs_in_fmt) or just start with a size that should cover 99% of your cases – maybe 200), and increase the guess until it works. Or you might try something like the snprintf() family of functions by Holger Weiss.

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

Sidebar

Related Questions

I have the following function: public static byte[] StringToByte(string str) { int length =
Suppose I have a static function template template<int I> void ft() within a struct
I have the following function: public static T TryGetArrayValue<T>(object[] array_, int index_) { ...
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have three classes that all have a static function called 'create'. I would
let's say i have a singleton object with a static function: static int MySingletonObject::getInt()
I want to have a static function which I declare in my .c file
So, I have a function pointer defined as: unsigned static int (*current_hash_function)(unsigned int); And
I have this function: static Dictionary<int, int> KeyValueDictionary = new Dictionary<int, int>(); static void
If you have the following function: static const map<ushort, ulong> MakeMap() { map<ushort, ulong>

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.