Bug 000287

When Created: 06/08/1999 06:00:14
Against DJGPP version: 2.02
By whom:
Abstract: stdarg doesn't work with floats
Example program:
#include <stdarg.h>

void test(int x, ...)
  va_list ap;
  va_start(ap, x);
  printf("%d %f\n", x, va_arg(ap, float));

void main()
  float f;
  f = 1.4;
  test(1, f);

1 36893488147419103232.000000

Note added: 06/08/1999 13:00:45
By whom:
Not a bug in DJGPP. A lack of understanding of the C language, mainly.

Floats can never be passed to any variable-arguments function.
They will get promoted to double, automatically. So you cannot
expect vararg(,) to give you back a float, either.

In the words of the ANSI/ISO C Standard: 

	If there is no actual next argument, or if `type` is not
	compatible with the type of the actual argumet (as promoted
	according to the default argument promotion rules), the	
	behaviour is undefined.

This also is the reason that printf(), unlike scanf() has no
separte formats at all for printing floats, or short ints, or
anything like that: they end up as doubles or normal ints
inside printf(), anyway, so there's no point to treat them

Closed on 06/08/1999 13:00:38: Non-bug: ANSI C violation in testing program.
By whom:

  webmaster     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010