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

The Archive Base Latest Questions

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

I’m trying to create a variable length function (obviously, heh) in C++, and what

  • 0

I’m trying to create a variable length function (obviously, heh) in C++, and what I have right now works, but only for the first argument. If someone could please let me know how to get this working with all the arguments that are passed, I would really appreciate it.

Code:

void udStaticObject::accept( udObjectVisitor *visitor, ... )
{
    va_list marker;
    udObjectVisitor *i = visitor;
    va_start( marker, visitor );
    while( 1 )
    {
        i->visit_staticObject( this );
//the if here will always go to the break immediately, allowing only 
//one argument to be used
        if( ( i = va_arg( marker, udObjectVisitor* ) ) )
            break;
    }
    va_end( marker );
}

Based on my past posts, and any help posts I make in general, there is probably some information that I did not provide that you will need to know to help. I apologize in advance if I forgot anything, and please let me know what you need to know so I can provide the information.

  • 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-15T11:36:51+00:00Added an answer on May 15, 2026 at 11:36 am

    If you use a variadic function, you need some way to tell the function how many arguments were passed. For example, printf() and friends take a formatting string that contains format specifiers for each of the passed arguments, and they count the number of format specifiers to determine how many arguments were passed.

    When passing a list of pointers, you can accomplish this “more simply” by passing a null pointer as the last argument. That way, you simply read arguments until you reach the null pointer.

    However, you should seriously consider not using a variadic function for this. You can accomplish the same behavior by taking a vector of pointers as a parameter and iterating over the contents of that vector. There are a number of reasons why this is superior to using a variadic function:

    • Variadic functions have absolutely no type safety. You lose any and all type information about the arguments when you pass them to a variadic function, so for example, a caller of your function could pass a numeric value instead of a pointer and you’d never be able to tell inside of your function.

    • With the variadic solution, the caller must correctly indicate the number of arguments. If the caller omits the null pointer at the end (or otherwise misinforms your function of how many arguments there are) and you try to read more arguments than were passed, you end up with undefined behavior. Right now you might say “well, that’s not hard to forget,” but inevitably, someone will forget or screw it up and debugging this sort of issue is a beating.

    • The solution taking a vector and iterating over its contents is far simpler to implement, easier to debug, and much more idiomatic in C++.

    Wherever there is an option between using a variadic function and not using a variadic function, you should prefer not to use a variadic function (I’ll admit, I have never written a variadic function in any of the C++ code I have written, though I’ve written a few in C).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.