www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000083

When Created: 05/09/1996 18:59:01
Against DJGPP version: 2.00
By whom: lehmann@mathematik.th-darmstadt.de
Abstract: stdarg doesn't work with last argument char
When using a variable length argument list with the last argument e.g. char,
the pointers used by va_arg are incorrect, since a copy of the variable value is
created in the local variable area. Since the va pointer is calculated relative
to this pointer, this doesn't work.

Solution added: 05/09/1996 19:13:57
By whom: lehmann@mathematik.th-darmstadt.de
Change the definition of va_start to use __builtin_next_arg, like
is used in the stdarg.h from gcc 2.7.2.
The same should probably be done for vararg (unless I misread it, it's
currently broken anyway).

Note added: 05/11/1996 13:29:41
By whom: lehmann@mathematik.th-darmstadt.de
OK, the current vararg implementation is not broken. But neverthess, I would
say it should be synced with the one in gcc 2.7.2, since it uses a builtin
that may tell the compiler that varargs is used and maybe turn off some
optimizations and it uses the ... syntax instead of a dummy argument, which
is probably preferable.

Note added: 07/19/1996 11:23:37
By whom: kor@cs.mcgill.ca
The following code fails as well:

#include <stdio.h>
#include <stdarg.h>

#define ENUM short unsigned int

void PrintBarAddress(ENUM, ...);

void main(void)
    char *  bar;

    printf("Passing bar address: %d
\n", (long) &bar);
    PrintBarAddress(1, (&bar));

void PrintBarAddress
    ENUM foo,
    va_list Arg;
    char **     barAddress;

    va_start(Arg, foo);
    barAddress = va_arg(Arg, char **);

    printf("Bar address: %d
\n", (long) barAddress);

Fixed in version 2.01 on 07/26/1996 00:19:38
By whom: dj@delorie.com

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010