Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Problems with <stdarg.h>
@ 1993-07-14 15:57 Ray Butterworth [MFCF]
  0 siblings, 0 replies; only message in thread
From: Ray Butterworth [MFCF] @ 1993-07-14 15:57 UTC (permalink / 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1993-07-14 15:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1993-07-14 15:57 Problems with <stdarg.h> Ray Butterworth [MFCF]

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