Re: K&R-Style Function Declarations: Good or Bad?

lawrence.jones_at_eds.com
Date: 12/10/03


Date: Wed, 10 Dec 2003 05:15:18 GMT

Dan Pop <Dan.Pop@cern.ch> wrote:
>
> I'm not sure about the behaviour of this code in K&R C, which talks about
> float parameters getting widened to double, but no mention about char and
> short parameters getting promoted to int.

As far as I know, all pre-ANSI compilers widened char and short
arguments to int (even if char was unsigned -- the first hint of
value-preserving conversion rules!). Behavior varied for unsigned char
and unsigned short: some compilers didn't support them at all, most
compilers widened them to unsigned int, a few (or maybe just one) used
ANSI-like value-preserving rules and widened them to either int or
unsigned int depending. Behavior also varied for the parameter
declarations -- some compilers converted the widened types back to the
declared types, other compilers quietly rewrote the parameter
declarations using the widened types (much as array declarations are
quietly rewritten as pointer declarations).

-Larry Jones

That's one of the remarkable things about life. It's never so
bad that it can't get worse. -- Calvin



Relevant Pages

  • Re: More structs
    ... int { ... Your phrase "similar ``non-struct'' declarations" I find ... void foo; ...
    (comp.lang.c)
  • Re: K&R-Style Function Declarations: Good or Bad?
    ... >> short parameters getting promoted to int. ... all pre-ANSI compilers widened char and short ... >declarations using the widened types (much as array declarations are ... K&R1 Appendix A explicitly mentions float ...
    (comp.lang.c)
  • Re: problem with the lower level i/o
    ... Ravi wrote: ... for the declarations of openand write. ... int fd,pid; ... char buf; ...
    (comp.unix.programmer)
  • Ordering local variables
    ... stack usage is extremely important. ... Suppose it has a number of int and char automatic variables. ... compiler might well be able to reorder the declarations to minimize ...
    (comp.lang.c)
  • Re: APPEND Option not recognized
    ... >> I remember when this error popped up I was trying to convince some very ... > at least some compilers where that is true. ... > C to assume char is 8 bits. ... In the first Cray C compiler, short, int, and long were all 64 ...
    (comp.lang.fortran)