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 160359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:01:15+00:00 2026-05-11T11:01:15+00:00

I have approximately 30 variadic functions. Each one accepts a path as the final

  • 0

I have approximately 30 variadic functions. Each one accepts a path as the final argument, e.g.:

bool do_foo(struct *f, int q, const char *fmt, ...) 

In each function, I have to check that the expanded format is less then or equal to a certain size. So, I find myself copy / pasting the same chunk of code to check for how many characters vsnprintf() didn’t print, set errno accordingly and bail out of the write.

What I would like to do is write a function to do this, which would return a statically allocated (expanded) string that is known to be a safe size, or newly initialized string on failure, which could be checked against NULL. The checks also have to determine if the string is an absolute or relative path, which influences the safe size of the string. It’s a lot of duplicate code and it’s starting to smell.

Is there a way that I can pass the contents of the elipsis from my function’s entry to another function? Or do I have to call va_start() first, and then pass the va_list to the helper function?

Edit:

I am not at all opposed to passing the va_list to the helper, I just wanted to make sure that nothing else existed. It seems to me the compiler understands where the variadic arguments begin, so I was just curious if I could tell it to pass them along.

  • 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. 2026-05-11T11:01:16+00:00Added an answer on May 11, 2026 at 11:01 am

    You can’t, you can only pass the arguments as a va_list. See the comp.lang.c FAQ.

    In general, if you’re writing variadic functions (that is, functions which take a variable number of arguments) in C, you should write two versions of each function: one which takes an ellipsis (...), and one which takes a va_list. The version taking an ellipsis should call va_start, call the version taking a va_list, call va_end, and return. There’s no need for code duplication between the two versions of the function, since one calls the other.

    A simple use-case could be:

    int vadd(int num_count, va_list args) {     int sum = 0;     for(int k = 0; k < num_count; k++) {         sum += va_arg(args, int);     }      return sum; }  int add(int num_count, ...) {     va_list args;     int sum = 0;      va_start(args, num_count);     sum = vadd(num_count, args);     va_end(args);      return sum; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is this what you are looking for? item.File.ServerRelativeUrl or if… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer There's also 'paredit. The cheat sheet shows you all the… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer From the sounds of it you may be (a) running… May 11, 2026 at 11:31 pm

Related Questions

I have a simple controller which returns images: public class ImageController : Controller {
I need to upload a massive (16GB, 65+ million records) CSV file to a
I'm trying to launch another process from a service (it's a console app that
I have been looking at the new database server we are setting up for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.