This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug in va_* macros for sparc-sun-solaris2.6


On Thu, 16 July 1998, 10:32:46, fedor@doc.com wrote:

 > RE: Bug in va_* macros - incorrect output of char argument
 > MACHINE: sparc-sun-solaris2.6, sparc-sun-solaris2.5.1, sparc-sun-sunos-4.1.4
 > COMPILER: egcs-1.0.1, gcc-2.8.0, gcc-2.8.1, gcc-2.7.2.3
 > 
 > The following test file illustrates a bug in sparc gcc. The output here is for
 > egcs-1.0.1, but the bug also appears in gcc-2.8.1, gcc-2.7.2.3 and egcs-1.0.1
 > for sparc-sun-sunos-4.1.4, and others...

All compilers are correct; the "print" function is declared to receive
a "char" as its first argument, but nothing is specified about the
following args, hence the compiler pushes all following args as "int".

 > 
 > The actual output is:
 > 
 > % gcc -v
 > Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.90.23/specs
 > gcc version egcs-2.90.23 980102 (egcs-1.0.1 release)
 > % gcc test-va.c
 > % ./a.out
 > <20>
 > <0>
 > %
 > 
 > While the correct output is:
 > % ./a.out
 > <20>
 > <21>
 > %
 > ----- test file ----
 > #include <stdio.h>
 > #include <stdarg.h>
 > 
 > void * print(char x,...);
 > 
 > void *
 > print(char x,...)
 > {
 >   char y, z;
 >   va_list ap;
 > 
 >   y = x;
 >   printf("<%d>\n", y);
 >   va_start(ap, x);
 >   z = va_arg(ap, char);

Here you should use:

     z = va_arg (ap, int);

and everything will work as expected.

 >   printf("<%d>\n", z);
 >   va_end(ap);
 >   return NULL;
 > }
 > 
 > int 
 > main()
 > {
 >   print((char)20, (char)21);
 >   return 0;
 > }
 > 
 > -- 
 > Adam Fedor               | Those who can't do, simulate
 > Digital Optics Co.       |
 > fedor@doc.com (MIME)     |------------------------------
 > fedor@gnu.org

manfred


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]