home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.sgi:11721 comp.sys.mips:826
- Path: sparky!uunet!olivea!hal.com!decwrl!csus.edu!netcomsv!cichlid!aab
- From: aab@cichlid.com (Andy Burgess)
- Newsgroups: comp.sys.sgi,comp.sys.mips
- Subject: varargs problem on MIPS processor
- Keywords: varargs mips
- Message-ID: <1992Jul31.192933.21622@cichlid.com>
- Date: 31 Jul 92 19:29:33 GMT
- Organization: SIlma Inc.
- Lines: 97
-
-
- We are running into a documented bug on an SGI platform
- and I was wondering if anyone had a workaround or at least an
- explanation of why it happens.
-
- Correct implementation of varargs is crucial for us as we market
- a programming environment that allows (on other platforms) interpreted
- patches to compiled code. Our patch mechanism relys on varargs to extract
- arbitrary arguments.
-
-
- Here is an excerpt from the varargs man page:
-
- --------------------
- BUGS
- Due to the procedure calling convention on the MIPS processor, floating-
- point parameters may be inaccessible via varargs unless they appear after
- a parameter of non-floating-point type. Thus, in the code sequence
- extern int foo(float,...);
-
- foo(1.0,2.0);
- the parameter 2.0 may be accessed incorrectly. If the function expected
- an intervening non-floating-point parameter, such as
- extern int foo(float,...);
-
- foo(1.0,4,2.0);
- the second floating-point parameter would be accessible as a double.
-
- --------------------
-
- Here is a small C program illustrating the problem:
-
- -------------------
- /* test varargs on sgi */
-
- #include "varargs.h"
-
- test(va_alist)
- va_dcl
- { va_list argp;
- double r;
-
- va_start(argp);
- r = va_arg(argp, double);
- printf("Should be 0.5: %lf\n", r);
- }
-
- test2(va_alist)
- va_dcl
- { va_list argp;
- double r;
- int i;
-
- va_start(argp);
- i = va_arg(argp, int);
- printf("Should be 100: %d\n", i);
- r = va_arg(argp, double);
- printf("Should be 0.5: %lf\n", r);
- }
-
- main()
- {
- test((double)0.5);
- test2(100, (double)0.5);
- }
-
-
- ------------------
-
- And the result:
-
- -----------------------
- % cc v.c && a.out
- Should be 0.5: 0.000000
- Should be 100: 100
- Should be 0.5: 0.500000
-
- ----------------------
- Our platform:
-
- Hardware:
- SGI 4D/70 GT
- 1 12 MHZ IP4 Processor
- FPU: MIPS R2010A/R3010 VLSI Floating Point Chip Revision: 1.5
- CPU: MIPS R2000A/R3000 Processor Chip Revision: 1.6
- OS:
- IRIX Release 4.0.1 System V
- --------------------
-
- Thanks for any and all help.
- I'll post a summary of responses.
- Andy
-
- --
- ==============================================================================
- Andrew A. Burgess aab@cichlid.com voice (408) 335 4779
- ==============================================================================
-