Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: rbutterw@math.uwaterloo.ca (Ray Butterworth [MFCF])
Subject: Problems with <stdarg.h>
Date: Wed, 14 Jul 1993 15:57:16 GMT	[thread overview]
Message-ID: <CA5wBH.3Jr@math.uwaterloo.ca> (raw)

<stdarg.h> seems to get the initial offset of the variable argument
list wrong in some cases.

I have a fix that seems to work for the problems that I ran into.


Script started on Wed Jul 14 10:20:37 1993


osf1# cc v.c

osf1# ./a.out
1   2   3.1   3.2   3.2   four


osf1# cc -DFIXIT v.c

osf1# ./a.out
1   2   3.1   3.2   four   five


osf1# cat v.c
#include <stdio.h>
#include <stdarg.h>

#if !defined(FIXIT)
    /* #define va_start(list, parmN) __builtin_va_start(list, parmN, 1) */
#else
#   undef va_start
#   define va_start(list, parmN) \
        (__builtin_va_start(list, parmN, 1), \
        (list).offset = ((char*)&parmN - (list).a0) \
                      + ((sizeof(parmN) + 7) & ~7))
#endif

static struct blivit { char *x1; char *x2; } thing = { "3.1", "3.2" };

    static void
test(int n1, int n2, struct blivit stuff, ...) {
    auto va_list args;
    auto char *a4;
    auto char *a5;

    va_start(args, stuff);

    a4 = va_arg(args, char*);
    a5 = va_arg(args, char*);

    printf("%d   %d   %s   %s   %s   %s\n",
        n1, n2,
        stuff.x1, stuff.x2,
        a4, a5);

    va_end(args);
}

main(int argc, char **argv) {
    test(1, 2, thing, "four", "five");
}

osf1# exit
script done on Wed Jul 14 10:21:12 1993


                 reply	other threads:[~1993-07-14 15:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox