home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / sgi / 11721 < prev    next >
Encoding:
Text File  |  1992-07-31  |  2.7 KB  |  109 lines

  1. Xref: sparky comp.sys.sgi:11721 comp.sys.mips:826
  2. Path: sparky!uunet!olivea!hal.com!decwrl!csus.edu!netcomsv!cichlid!aab
  3. From: aab@cichlid.com (Andy Burgess)
  4. Newsgroups: comp.sys.sgi,comp.sys.mips
  5. Subject: varargs problem on MIPS processor
  6. Keywords: varargs mips
  7. Message-ID: <1992Jul31.192933.21622@cichlid.com>
  8. Date: 31 Jul 92 19:29:33 GMT
  9. Organization: SIlma Inc.
  10. Lines: 97
  11.  
  12.  
  13. We are running into a documented bug on an SGI platform
  14. and I was wondering if anyone had a workaround or at least an
  15. explanation of why it happens.
  16.  
  17. Correct implementation of varargs is crucial for us as we market 
  18. a programming environment that allows (on other platforms) interpreted
  19. patches to compiled code. Our patch mechanism relys on varargs to extract
  20. arbitrary arguments.
  21.  
  22.  
  23. Here is an excerpt from the varargs man page:
  24.  
  25. --------------------
  26. BUGS
  27.      Due to the procedure calling convention on the MIPS processor, floating-
  28.      point parameters may be inaccessible via varargs unless they appear after
  29.      a parameter of non-floating-point type.  Thus, in the code sequence
  30.           extern int foo(float,...);
  31.  
  32.           foo(1.0,2.0);
  33.      the parameter 2.0 may be accessed incorrectly.  If the function expected
  34.      an intervening non-floating-point parameter, such as
  35.           extern int foo(float,...);
  36.  
  37.           foo(1.0,4,2.0);
  38.      the second floating-point parameter would be accessible as a double.
  39.  
  40. --------------------
  41.  
  42. Here is a small C program illustrating the problem:
  43.  
  44. -------------------
  45. /* test varargs on sgi */
  46.  
  47. #include "varargs.h"
  48.  
  49. test(va_alist)
  50.   va_dcl
  51. {       va_list argp;
  52.         double r;
  53.  
  54.         va_start(argp);
  55.         r = va_arg(argp, double);
  56.         printf("Should be 0.5: %lf\n", r);
  57. }
  58.  
  59. test2(va_alist)
  60.   va_dcl
  61. {       va_list argp;
  62.         double r;
  63.         int i;
  64.  
  65.         va_start(argp);
  66.         i = va_arg(argp, int);
  67.         printf("Should be 100: %d\n", i);
  68.         r = va_arg(argp, double);
  69.         printf("Should be 0.5: %lf\n", r);
  70. }
  71.  
  72. main()
  73. {
  74.         test((double)0.5);
  75.         test2(100, (double)0.5);
  76. }
  77.  
  78.  
  79. ------------------
  80.  
  81. And the result:
  82.  
  83. -----------------------
  84. % cc v.c && a.out
  85. Should be 0.5: 0.000000
  86. Should be 100: 100
  87. Should be 0.5: 0.500000
  88.  
  89. ----------------------
  90. Our platform:
  91.  
  92. Hardware:
  93.   SGI 4D/70 GT
  94.   1 12 MHZ IP4 Processor
  95.   FPU: MIPS R2010A/R3010 VLSI Floating Point Chip Revision: 1.5
  96.   CPU: MIPS R2000A/R3000 Processor Chip Revision: 1.6
  97. OS:
  98.   IRIX Release 4.0.1 System V
  99. --------------------
  100.  
  101. Thanks for any and all help.
  102. I'll post a summary of responses.
  103. Andy
  104.  
  105. -- 
  106. ==============================================================================
  107. Andrew A. Burgess            aab@cichlid.com              voice (408) 335 4779
  108. ==============================================================================
  109.