[OpenAFS-devel] Re: OpenAFS CVS Commit: openafs/src/util by shadow

Russ Allbery rra@stanford.edu
Tue, 01 Jul 2003 16:08:25 -0700


cvs <cvs@GRAND.CENTRAL.ORG> writes:

> this probably needs a better fix. however, one some platforms, we see:
> ./snprintf.c: In function `afs_vsnprintf':
> ./snprintf.c:227: `short int' is promoted to `int' when passed through `...'
> ./snprintf.c:227: (so you should pass `int' not `short int' to `va_arg')

> and it won't compile. are there platforms where short is correct?

No.  C always promotes short to int when passing through ..., so you
should always pass int to va_arg and then cast the result to short when
assigning it (or just assign it to a short variable, which will cast it
automatically).

Similarly for float and double.

The text from the ISO 1999 standard in 6.5.2.2 is:

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

7 If the expression that denotes the called function has a type that does
  include a prototype, the arguments are implicitly converted, as if by
  assignment, to the types of the corresponding parameters, taking the
  type of each parameter to be the unqualified version of its declared
  type. The ellipsis notation in a function prototype declarator causes
  argument type conversion to stop after the last declared parameter. The
  default argument promotions are performed on trailing arguments.

where integer promotions are defined in 6.3.1.1 as:

  If an int can represent all values of the original type, the value is
  converted to an int; otherwise, it is converted to an unsigned
  int. These are called the integer promotions.48) All other types are
  unchanged by the integer promotions.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>