Make va_arg(ap,double) work correctly.

This was not working because floating-point arguments are really passed in the extended format, but based on the wording in the C standard a type of "double" should still work for arguments passed with that type.

This fixes #29. (The bug report was valid only with respect to double, not float or long double.)
This commit is contained in:
Stephen Heumann 2021-09-03 21:25:20 -05:00
parent 92f1344a6e
commit 438942692a
2 changed files with 7 additions and 1 deletions

View File

@ -27,7 +27,9 @@ typedef char *__va_list[2];
typedef __va_list va_list;
#define va_end(a) __va_end(a)
#define va_start(ap,LastFixedParm) ((void) ((ap)[0] = (ap)[1] = (char *) (&LastFixedParm + 1)))
#define va_arg(ap,type) ((type *)((ap)[0] += sizeof(type)))[-1]
#define va_arg(ap,type) _Generic(*(type *)0, \
double: (type)((long double *)((ap)[0] += sizeof(long double)))[-1], \
default: ((type *)((ap)[0] += sizeof(type)))[-1])
void __va_end(va_list);

View File

@ -1215,6 +1215,10 @@ int foo(int[42]);
162. In certain cases, an assignment from a location with an 8-bit type to a location with a 16-bit type might store the wrong value.
163. When an argument of type double was passed to a function taking variable arguments, va_arg(ap,double) would not retrieve it correctly.
(Devin Reade)
-- Bugs from C 2.1.0 that have been fixed -----------------------------------
1. In some situations, fread() reread the first 1K or so of the file.