🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #52668

Re: prototypes with short args generate fatal error

#52668
From: Kevin Rodgers
Date: Tue, 09 Jun 1992 00:15
43 lines
2607 bytes
In article <1992Jun8.174919.25532@cichlid.com> aab@cichlid.com (Andy Burgess) writes:
>The following code does not compile using gcc 2.1 on SunOS 4.1.1.
>Is the C code indeed illegal and if so what would the justification be?
>I ran into this while trying to compile xmon in the X11R5 distribution.
>Using cc (SC1.0 1Mar1991) it compiles without error.
>
>----------------------
>int foo(short x);
>int bar(short x);
>
>int foo(short x) {} /* this works */
>
>int bar(x) short x; {} /* this does not */
>---------------------
>gcc bug.c
>bug.c: In function `bar':
>bug.c:6: argument `x' doesn't match function prototype
>bug.c:6: a formal parameter type that promotes to `int'
>bug.c:6: can match only `int' in the prototype

The program is indeed illegal.  From section 9.2.2 (Mixing Prototype and
Non-Prototype Declarations) of "C: A Reference Manual" by Samuel P.
Harbison & Guy L. Steele, Jr.:

      A function type declared in prototype form is compatible with a
   non-prototype function definition if:

      1. the return types are compatible.
      2. the prototype does not include the ellipsis terminator.
      3. the number of parameters in the prototype and the function
         definition is the same, and
      4. the type of the _i_th parameter in the prototype is compatible
         with the type resulting from applying the usual argument
         conversions to the _i_th parameter in the definition.

Since the usual unary conversion of a short argument is to an int
(section 6.3.3), and two arithmetic types can be compatible only if they
are the same type (section 5.11.1), condition 4 above is not satisfied.
-- 
Kevin Rodgers				kevin@traffic.den.mmc.com
Martin Marietta MS A16401		(303) 790-3971
116 Inverness Dr. East
Englewood CO 80112 USA			GO BUFFS!
Technical Details
Message-ID: <1992Jun9.001551.18601@den.mmc.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!news.den.mmc.com!traffic!kevin
References: <1992Jun8.174919.25532@cichlid.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,b21c3ee4f807878a
X-Google-Attributes: gid11318c,public
X-Google-Thread: 1014db,b21c3ee4f807878a
X-Google-Attributes: gid1014db,public
X-Google-ArrivalTime: 1992-06-08 13:25:38 PST
Newsgroups: gnu.gcc.help,comp.lang.c
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!news.den.mmc.com!traffic!kevin
From: kevin@traffic.den.mmc.com (Kevin Rodgers)
Subject: Re: prototypes with short args generate fatal error
Message-ID: <1992Jun9.001551.18601@den.mmc.com>
Sender: news@den.mmc.com (News)
Nntp-Posting-Host: traffic.den.mmc.com
Organization: Martin Marietta Western Internal Systems
References: <1992Jun8.174919.25532@cichlid.com>
Date: Tue, 9 Jun 1992 00:15:51 GMT
Lines: 43