can't pass char through va_list

Jon Wilkening wilkenin@math.lbl.gov
Thu May 4 12:15:00 GMT 2000


Hello,
  The following code doesn't work right with gcc-2.95.2
running on a sun ultra-1 under solaris 2.7:

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

void test(int d, ...) {
  va_list ap;
  char buf[4]={'a','b','c','\0'};
    
  va_start(ap, d);
  buf[2] = va_arg(ap, char);
  printf("%s\n", buf);
  va_end(ap);
}

main() {
  test(1, '7');
}


  The result should be

ab7

  but instead I get

ab

  It works correctly on an intel pentium III running red hat linux 6.0,
or if you change char to int in va_arg(ap,char).  (I didn't compile
with any flags.  just gcc va_arg.c)


Thank you,

Jon Wilkening



More information about the Gcc-bugs mailing list