🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #2636

Re: prototyping short and float --- READ THIS

#2636
From: Roland McGrath
Date: Sat, 13 May 1989 19:58
43 lines
1719 bytes
This seems to be a common problem, so read this and remember it!

You cannot intermix traditional (non-prototype) definitions and prototype
declarations of functions whose arguments are of types that get widened.

In C, [unsigned] short and char get widened to [unsigned] int, and float
gets widened to double, normally.

However, in the presence of a prototype declaration, the compiler does NOT
do this widening, since both the function and the caller know exactly what
types are being used.

The non-prototype definition:

void
func(x)
short x;
{ ... }

is essentially equivalent to:

void
func(temp)
int temp;
{
  short int x = (short) temp;
}

The solution to your problem is to either write the prototypes with the
widened types:

void f1(int a1);
void f2(double a2);

or to write your functions with prototype definitions:

void f1(short a1) { ... }
void f2(double a2) { ... }
--
	Roland McGrath
	Free Software Foundation, Inc.
roland@ai.mit.edu, uunet!ai.mit.edu!roland
Copyright 1989 Roland McGrath, under the GNU General Public License, version 1.
Technical Details
Message-ID: <MCGRATH.89May13125817@tully.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!rutgers!apple!bloom-beacon!shelby!agate!tully.Berkeley.EDU!mcgrath
References: <8905131941.AA16561@troilus.stolaf.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!rutgers!apple!bloom-beacon!shelby!agate!tully.Berkeley.EDU!mcgrath
From: mcgrath@tully.Berkeley.EDU (Roland McGrath)
Newsgroups: gnu.gcc.bug
Subject: Re: prototyping short and float --- READ THIS
Message-ID: <MCGRATH.89May13125817@tully.Berkeley.EDU>
Date: 13 May 89 19:58:17 GMT
References: <8905131941.AA16561@troilus.stolaf.edu>
Sender: usenet@agate.BERKELEY.EDU
Distribution: gnu
Organization: Hackers Anonymous International, Ltd., Inc. (Applications welcome)
Lines: 43
In-reply-to: tuecke@TROILUS.ACC.STOLAF.EDU's message of 13 May 89 19:41:35 GMT