🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2387

Strange behaviour with old-style code

#2387
From: Richard Sargent
Date: Wed, 06 Feb 1991 19:06
57 lines
2104 bytes
I have come across a compiler which does something very unusual
in its handling of old-style functions. Is there anyone who knows
whether the following behaviour is either permitted or forbidden
by the ANSI Standard for C?

Thanks.

====================================================================
The compiler passes floats widened to doubles, and the routine pulls
the values off the stack using the appropriate widened addressing,
but then proceeds to use the "declared" argument type to do single
precision floating point arithmetic. A colleague of mine has
crawled through the Standard as well as K&R II, but found nothing
that explicitly addresses this issue.

The following program shows what happens:


	main()
	{
		printf("sizeof(float)=%d, sizeof(double)=%d\n",
			sizeof(float), sizeof(double));

		/* note: no prototypes in scope */
		bar(1.5);
	}

	int
	bar(u)
	float u;
	{
		printf("old style func: u=%f, sizeof(u)=%d\n", u, sizeof(u));
	}



The results are (under this particular compiler):

  sizeof(float)=4, sizeof(double)=8
  old style func: u=1.500000, sizeof(u)=4 


The call to bar() should be fine since both the call and the function
definition are old style K&R.  In the interest of upward compatibility
with the old K&R C, the formal and actual parameters to bar() are
supposed to be promoted to double and used as double.  
               ^^done^^               ^^^^ I question this.


Inquiring minds want to know...


p.s.
This example shows only a single argument used. The real code
used several arguments. All values were addressed from the
stack correctly. It is just the question of "using" the float
argument as a float, rather than the implicit "double".
Technical Details
Message-ID: <1991Feb6.190607.11731@alias.uucp>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!geac!alias!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!geac!alias!news
From: rsargent@alias.UUCP (Richard Sargent)
Newsgroups: comp.std.c
Subject: Strange behaviour with old-style code
Message-ID: <1991Feb6.190607.11731@alias.uucp>
Date: 6 Feb 91 19:06:07 GMT
Sender: news@alias.uucp (USENET News)
Organization: Alias Research Inc., Toronto ON Canada
Lines: 57