Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Integer promotion of function parameters

Reply
Thread Tools

Integer promotion of function parameters

 
 
=?ISO-8859-15?Q?Jean=2DFran=E7ois?= Lemaire
Guest
Posts: n/a
 
      10-22-2007
Hello,

I'm having a discussion with someone who sustains that function
parameters, when they are smaller than an int (say short or char) are
automatically promoted to int before being passed to the caller.

Despite looking in the Standard (ISO/IEC 9899:TC2), &6.5.2.2 "Function
calls", I'm still unsure, because this is rather technical reading.

Can someone enlighten me?

Thanks,

JFL
--
Jean-François Lemaire
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      10-22-2007
Jean-François Lemaire wrote On 10/22/07 17:18,:
> Hello,
>
> I'm having a discussion with someone who sustains that function
> parameters, when they are smaller than an int (say short or char) are
> automatically promoted to int before being passed to the caller.
>
> Despite looking in the Standard (ISO/IEC 9899:TC2), &6.5.2.2 "Function
> calls", I'm still unsure, because this is rather technical reading.
>
> Can someone enlighten me?


Three paragraphs seem important:

- 6.5.2.2p6 defines the "default argument promotions"
and describes when they are used.

- 6.5.2.2p7 describes when the default argument promotions
are *not* used, and what happens instead.

- 6.3.1.1p2 defines the "integer promotions," which make
up part of the default argument promotions.

In ordinary language: Your friend is right, but only
when prototypes are not used or for arguments that match
the `...' of a variable parameter list. Different rules
apply when a prototype supplies information about the type
of the parameter corresponding to an argument.


--
http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      10-22-2007
Jean-François Lemaire said:

> Hello,
>
> I'm having a discussion with someone who sustains that function
> parameters, when they are smaller than an int (say short or char) are
> automatically promoted to int before being passed to the caller.
>
> Despite looking in the Standard (ISO/IEC 9899:TC2), &6.5.2.2 "Function
> calls", I'm still unsure, because this is rather technical reading.
>
> Can someone enlighten me?


"If the expression that denotes the called function has a type that does
not include a prototype, the integral promotions are performed on each
argument and arguments that have type float are promoted to double. These
are called the default argument promotions."

"Integral promotions" means that char, short, int bit-fields, in both
signed and unsigned flavours, and enums, can all be used in an expression
wherever an int or unsigned int can be used, and in fact *are* so used,
with the promotion being to int if an int can represent all values of the
original type, or to unsigned int otherwise.

So yes, ***in the absence of a function prototype***, char and short are
certainly promoted either to int or unsigned int when used as, or in,
function arguments. In the presence of a function prototype, I think you
need to talk to someone like David, Eric, Dik or Chris.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
=?ISO-8859-15?Q?Jean=2DFran=E7ois?= Lemaire
Guest
Posts: n/a
 
      10-23-2007
On Tuesday 23 October 2007 01:10, Richard Heathfield wrote:

[...]

> So yes, ***in the absence of a function prototype***, char and short
> are certainly promoted either to int or unsigned int when used as, or
> in, function arguments. In the presence of a function prototype, I
> think you
> need to talk to someone like David, Eric, Dik or Chris.


This was a somewhat rhetorical question anyway, so your answer and Eric
Sosman's are more than adequate, particularly since they confirm my own
understanding of the Standard

Thanks to both of you.
--
Jean-François Lemaire
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Integer promotion, relational operators, and unequal integer ranks. charles_gero@merck.com C Programming 1 01-15-2007 11:21 PM
Integer promotion and overflow Russell Shaw C Programming 20 01-03-2005 08:31 PM
Data Recovery Book and Online Business Promotion, Products Sales Promotion, Search Engine Optimization and Online Data Recovery Training services Author Tarun Tyagi Cisco 0 12-15-2004 01:52 AM
The promotion code "MSUU4C8E3475" is not a valid promotion code Sam-Hong Kong MCDST 2 03-04-2004 06:47 PM
Question about bitfield promotion/cast to integer Ray C Programming 4 01-06-2004 04:10 AM



Advertisments