* may be a little CXX bug on ALPHA in stdarg with float.
@ 1995-09-27 4:00 Jean-Louis Moser
1995-09-27 4:00 ` Daniel S. Riley
1995-10-10 4:00 ` Mark Charette
0 siblings, 2 replies; 3+ messages in thread
From: Jean-Louis Moser @ 1995-09-27 4:00 UTC (permalink / raw)
| May be here is a bug in DEC C++ V5.0-3 for DEC OSF/1 (Alpha).
#include <iostream.h>
#include <stdarg.h>
void foo (float a, ...)
{
va_list list;
va_start (list, a);
while (a != 0) {
cout << a << " ";
a = va_arg (list, float);
}
cout << endl; va_end (list);
}
void main ()
{
foo (1.0f,2.0f,3.0f,4.0f,0);
}
the result is : 1 (it may be: 1 2 3 4)
when we replace float with short, int, double, or struct A {long x_; long y_;};
it work fine. There is the same problem with cc and GNU g++.
--
+----------------------------+------------------------------------+
| Jean-Louis Moser | 2001 SA |
| tel: 33 (1)46.66.54.54 | 2, rue de la renaissance |
| Email: jlm@two-oo-one.fr | F-92184 Antony Cedex |
+----------------------------+------------------------------------+
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: may be a little CXX bug on ALPHA in stdarg with float.
1995-09-27 4:00 may be a little CXX bug on ALPHA in stdarg with float Jean-Louis Moser
@ 1995-09-27 4:00 ` Daniel S. Riley
1995-10-10 4:00 ` Mark Charette
1 sibling, 0 replies; 3+ messages in thread
From: Daniel S. Riley @ 1995-09-27 4:00 UTC (permalink / raw)
In article <JLM.95Sep27162853@ludo.two-oo-one.fr>
jlm@ludo.two-oo-one.fr (Jean-Louis Moser) writes:
jlm> | May be here is a bug in DEC C++ V5.0-3 for DEC OSF/1 (Alpha).
Nope, don't think so.
jlm> void foo (float a, ...)
jlm> void main ()
jlm> {
jlm> foo (1.0f,2.0f,3.0f,4.0f,0);
jlm> }
As in C, any argument for which there is no parameter is subject to
the usual default promotions, so (regardless of what you may have
intended) 2.0f, 3.0f and 4.0f are passed as doubles, not floats. The
call should be
foo (1.0f,2.0f,3.0f,4.0f,0.0);
0 won't do -- it has to be the length of a double, so an int is too
short. The type given to va_arg must be the type after any promotions
have been applied, so the values should be retrieved with
a = va_arg (list, double);
--
Dan Riley Internet: dsr@lns598.lns.cornell.edu
Wilson Lab, Cornell University HEPNET/SPAN: lns598::dsr (44630::dsr)
"Distance means nothing/To me." -Kate Bush
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: may be a little CXX bug on ALPHA in stdarg with float.
1995-09-27 4:00 may be a little CXX bug on ALPHA in stdarg with float Jean-Louis Moser
1995-09-27 4:00 ` Daniel S. Riley
@ 1995-10-10 4:00 ` Mark Charette
1 sibling, 0 replies; 3+ messages in thread
From: Mark Charette @ 1995-10-10 4:00 UTC (permalink / raw)
Jean-Louis Moser (jlm@ludo.two-oo-one.fr) wrote:
: | May be here is a bug in DEC C++ V5.0-3 for DEC OSF/1 (Alpha).
: #include <iostream.h>
: #include <stdarg.h>
: void foo (float a, ...)
: {
: va_list list;
: va_start (list, a);
: while (a != 0) {
: cout << a << " ";
: a = va_arg (list, float);
: }
: cout << endl; va_end (list);
: }
: void main ()
: {
: foo (1.0f,2.0f,3.0f,4.0f,0);
: }
: the result is : 1 (it may be: 1 2 3 4)
: when we replace float with short, int, double, or struct A {long x_; long y_;};
: it work fine. There is the same problem with cc and GNU g++.
From Programmer's Quick Reference Series, Standard C (Plauger & Brodie), Page
142 (va_start)
The last argument must not have register storage class, and it must have a
type that is not changed by the translator. (It cannot have an array type,
a function type, type float, or any integer type that changes when promoted).
Your va_start does not meet these requirements.
--
Mark Charette charette@mika.com
MIKA Systems, Inc
17197 N. Laurel Park Dr Suite 115
Livonia, MI 48152
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1995-10-10 4:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-09-27 4:00 may be a little CXX bug on ALPHA in stdarg with float Jean-Louis Moser
1995-09-27 4:00 ` Daniel S. Riley
1995-10-10 4:00 ` Mark Charette
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox