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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:05:05+00:00 2026-06-18T10:05:05+00:00

There is a function my_init(…) that uses a variable argument list. The length of

  • 0

There is a function my_init(…) that uses a variable argument list. The length of this list is not known, but there is a maximum of 100 and the elements are always char-arrays (means plain C-strings).

That’s how I try to decode them:

void my_init(...)
{
    va_list vl; 
    int     tagCnt,tagLen=100; 
    char   *listTag,*listValue;

    va_start(vl,tagLen);
    for (tagCnt=0; tagCnt<50; tagCnt++)
    {
        listTag=va_arg(vl,char*);
        if (listTag==0) break;
        listValue=va_arg(vl,char*);

        ... // do some usefult things here
    }
    va_end(vl);
}

…and I call this function this way:

my_init("tag1","value1",
        "tag2","value2",
        0);

So there are always pairs and the end of a list is marked with a 0. Unfortunately my_init() fails, after calling va_start() vl contains some crap that has nothing to do with input parameters and the calls to va_arg() return invalid pointers. So what is wrong in my code?

The code given above is shortened a bit so may be it does not compile…

Thanks!

==================================================================================

EDIT:

I changed code and call this way:

void my_init(int dummy,...)
{
    va_list vl; 
    int     tagCnt,tagLen=100; 
    char   *listTag,*listValue;

    va_start(vl,dummy);
    for (tagCnt=0; tagCnt<50; tagCnt++)
    {
        listTag=va_arg(vl,char*);
        if (listTag==0) break;
        listValue=va_arg(vl,char*);

        ... // do some usefult things here
    }
    va_end(vl);
}

my_init(0,
        "tag1","value1",
        "tag2","value2",
        0);

Independent from the used header file I now get other crap in my vl, stdargs.h or varargs.h do not make a difference…

  • 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-18T10:05:06+00:00Added an answer on June 18, 2026 at 10:05 am

    The second argument to va_start must be the last named function parameter. In other words, the canonical usage is this:

    void my_func(int arg1, float arg2, ...) {
    
        va_list vl;
    
        va_start(vl, arg2);
    
        // Stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a function in my program. With the cout statement there the program
Is there such a thing? I know that I can hook my function on
Is there a way to get the list index name in my lapply() function?
Is there a way I can get this array walk with my anonymous function
There's a addPost function in my router. I don't want to re-create the postAddView
Is there a better way to handle my FindAdjacent() function for my A Star
There has to be a better way of writing the js in my function....
Is there any way I can make Firefox call a JavaScript function in my
how do I make my swap function in java if there is no method
Is there any way to add my own completion to an (interactive) elisp function?

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.