[comp.lang.c] VAX

jnh@ece-csc.UUCP (Joseph Nathan Hall) (05/27/88)

The program

	void test(float x, float y, float z)
	{
		printf("%f %f %f", x, y, z);
	}

	main ()
	{
		float x, y, z;
		test(1.0, 2.0, 3.0);
		x = 1.0;
		y = 2.0;
		y = 3.0;
		test(x, y, z);
	}

produces the quixotic output

	1.000000 2.000000 1.000000
	3.000000 2.000000 3.000000

on my machine.  I'm running VAX C 2.3-024 on VAX/VMS 4.6, on a VAXstation II
GPX.  Versions of this where test is declared old-style and where x, y, and
z in the new-style declaration are double work fine.

Am I losing it, or is this as FUBAR as it seems?

-- 
v   v sssss|| joseph hall                      || 201-1D Hampton Lee Court
 v v s   s || jnh@ece-csc.ncsu.edu (Internet)  || Cary, NC  27511
  v   sss  || the opinions expressed herein are not necessarily those of my
-----------|| employer, north carolina state university . . . . . . . . . . . 

jnh@ece-csc.UUCP (Joseph Nathan Hall) (05/27/88)

Pardon me for a couple of typos:  the second 'y =' should be

	z = 3.0 (obviously)

and the actual output is

	1.000000 2.000000 1.000000
	1.000000 2.000000 1.000000

More notes:  the results are the same if you cc/prec=sing and/or /noopt
and/or if you cast the arguments float:

	test((float) 1.0, (float) 2.0, (float) 3.0) ...


-- 
v   v sssss|| joseph hall                      || 201-1D Hampton Lee Court
 v v s   s || jnh@ece-csc.ncsu.edu (Internet)  || Cary, NC  27511
  v   sss  || the opinions expressed herein are not necessarily those of my
-----------|| employer, north carolina state university . . . . . . . . . . . 

jnh@ece-csc.UUCP (Joseph Nathan Hall) (05/28/88)

In article <3615@ece-csc.UUCP> jnh@ece-csc.UUCP (Joseph Nathan Hall) writes:
>Pardon me for a couple of typos:  the second 'y =' should be

In fact, pardon me for posting this.  (Our rn isn't retracting postings
properly, sorry.)  The example posted *does* work correctly.  It was an
attempt to determine exactly what the problem was with an application I am
writing.

I have now nailed down the problem.  I'm not sure I would characterize it as
a bug, but I would characterize it as a deficiency.

What was happening was that my prototype, which included some float
declarations, was accidentally followed by an old-style declaration with
no parameter list.

Apparently the second, old-style declaration superseded the new-style
declaration, causing the automatic coercion of floats to doubles.  This
occurred *without* any warning or comment from the compiler.

Sorry, again, for the wasted bandwidth.

-- 
v   v sssss|| joseph hall                      || 201-1D Hampton Lee Court
 v v s   s || jnh@ece-csc.ncsu.edu (Internet)  || Cary, NC  27511
  v   sss  || the opinions expressed herein are not necessarily those of my
-----------|| employer, north carolina state university . . . . . . . . . . . 

karl@haddock.ISC.COM (Karl Heuer) (06/01/88)

In article <3616@ece-csc.UUCP> jnh@ece-csc.UUCP (Joseph Nathan Hall) writes:
>I have now nailed down the problem.  I'm not sure I would characterize it as
>a bug, but I would characterize it as a deficiency.  [A function was declared
>twice, once with a prototype and once with an old-style declaration.  The
>second one overrode the first.]

I believe that it is a bug, according to the dpANS specification.  As I read
it, the new rules apply as long as there is any prototype in scope--having a
non-prototype declaration also in scope doesn't change that.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint