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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:26:19+00:00 2026-05-21T17:26:19+00:00

For example, something like this: #include <cstdarg> void my_function(int it=42, …) { /* va_list/start/arg/end

  • 0

For example, something like this:

#include <cstdarg>

void my_function(int it=42, ...)
{
     /* va_list/start/arg/end code here */
}

What exactly does the above code mean in C++? It compiles fine in G++. Note, I can’t imagine any scenario where this would be useful or even what it ought to do. I’m just curious.

  • 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-21T17:26:20+00:00Added an answer on May 21, 2026 at 5:26 pm
    void my_function(int it=42, ...)
    

    You said this function compiles fine with GCC, but you cannot make use of the default argument, you will have to pass argument for the so-called default parameter as well, to work with this function.

    my_function("string", 98, 78, 99); //error
    my_function(898, "string", 98, 78, 99); //ok, but the param 'it' becomes 898
    

    Ask yourself:

    Is the first argument 898 corresponds to the parameter it or it corresponds to the variadic parameter (and you intend to use the default value 42 for it)?

    The compiler cannot know your intention!

    BTW @Johannes pointed out a good point : you can simply call my_function() without passing any argument. That is the only instance I see when you can make use of the default argument.


    Now if you change the position of the default parameter, something like this:

    void f(..., int p = 10); //illegal
    

    Then this is illegal in C++ to begin with.

    Again, ask yourself : if it was allowed then you could call this as:

    f(9879, 97897, 7897);
    

    Is the last argument 7897 corresponds to the parameter p or it corresponds to the variadic parameter (and you intend to use the default value 10 for p)?

    The compiler cannot know your intention in this case either.

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

Sidebar

Related Questions

For example, if I have something like this: #include filename.h When I select filename.h
I've seen several examples of code like this: if not someobj: #do something But
I'm looking for something like break for loops. Here's some example code (using Symfony's
I would like to see how this example of existing code would be able
For example, in my error_log, it says something like: Error... require, include, a_function, another_function
I usually do something like the example below when I need to return error
For example, given a type param method i'm looking for something like the part
When I try to use curl or file_get_contents to read something like http://example.com/python/json/ from
For example, if I make a query like between(1,4,X)? I would expect something like
What's an example of something dangerous that would not be caught by the code

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.