Find the answer to your Linux question:
Results 1 to 2 of 2
Hi Guys, I have a problem creating va_list variable on zLinux platform. Here is the code that i had written to create va_list variable va_list INVALID_VA_LIST = NULL; va_list bar(void ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    1

    Post Problem creating va_list variable on zLinux

    Hi Guys,
    I have a problem creating va_list variable on zLinux platform.
    Here is the code that i had written to create va_list variable

    va_list INVALID_VA_LIST = NULL;
    va_list bar(void **vals)
    {
    int numvals=0;
    void **out=NULL;

    for (numvals = 0; vals[numvals]; ++numvals) {}
    out = (void **)malloc (numvals * sizeof (void *));
    if (!out)
    return INVALID_VA_LIST;

    memcpy (out, vals, sizeof (void *) * numvals);
    return (va_list)out;
    }

    int main() {
    const char *lists[] = { "hi", "ho", "off we go", NULL };
    va_list arglist = bar((void**)lists);
    char *vval;
    while((vval = va_arg(arglist, char *)) != NULL){
    printf("%s\n",vval);
    }

    This use to work on Linux platform (Like Red Hat, Suse), but this is not working in zLinux platform and i could not find any work around for this, since i have to pass dynemic number of arguments to a function i want to create the va_list varialbe.
    As per some forums i have read that va_list in zLinux is a structure, can any one help me creating a va_list variable on zLinux platform.

    Thanks in advance...

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    It is never a good idea to pretend to know the internals of a variable of type va_list. The C standard allows the implementer to structure it any way he or she wishes, as long as it behaves as documented.

    The only permissible ways to manipulate a variable of type va_list is with the following.
    1. va_start()
    2. va_arg()
    3. va_end()
    4. va_copy()

    (I was about to say "with the following functions", but you should not assume that none of them are macros.)

    For more information about these, do this at the command line:
    Code:
    man 3 stdarg
    If man pages are not installed on your system, google this:
    Code:
    man stdarg Linux
    It does not appear that stdarg is what you want to use here.

    Instead, just use a pointer of pointers to void, as you're already doing, and pass that back and forth.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...