Path: utzoo!utgpu!water!watmath!rbutterworth From: rbutterworth@watmath.waterloo.edu (Ray Butterworth) Newsgroups: comp.lang.c Subject: Re: parameter adjustment (was double indirection) Message-ID: <16940@watmath.waterloo.edu> Date: 15 Feb 88 14:42:25 GMT References: <4292@rosevax.Rosemount.COM> <2292@umd5.umd.edu> Organization: U of Waterloo, Ontario Lines: 70 In article <2292@umd5.umd.edu>, chris@trantor.umd.edu (Chris Torek) writes: > Now then, on to parameters: > There are no array parameters in C. While you can declare > a parameter as `array of ', or even (belying what I > said above) as `array of ', the parameter's type is NOT > `array of '. It is quietly adjusted by the compiler > to `pointer to '. > NONE OF THE ABOVE APPLIES TO `ordinary' VARIABLE DECLARATIONS--- > ONLY PARAMETER ARRAY DECLARATIONS ARE `adjusted'. C preforms this "helpful" adjustment of the programmer's misdeclaration with other parameters too. Consider this program (BSD 4.3): % cat sizeof.c #include test(f, d, s, c, a) float f; double d; short s; char c; int a[10]; { auto float af; auto double ad; auto short as; auto char ac; auto int aa[10]; fprintf(stdout, "sizeof args: float=%d double=%d short=%d char=%d int[10]=%d\n", (int)sizeof(f), (int)sizeof(d), (int)sizeof(s), (int)sizeof(c), (int)sizeof(a)); fprintf(stdout, "sizeof autos: float=%d double=%d short=%d char=%d int[10]=%d\n", (int)sizeof(af), (int)sizeof(ad), (int)sizeof(as), (int)sizeof(ac), (int)sizeof(aa)); } int array[10]; main() { test(0., 0., 0, 0, array); return 0; } %lint sizeof.c (not BSD lint) sizeof.c: sizeof.c(4): warning: float type changed to double sizeof.c(8): warning: array[10] type changed to pointer % cc sizeof.c && ./a.out sizeof args: float=8 double=8 short=2 char=1 int[10]=4 sizeof autos: float=4 double=8 short=2 char=1 int[10]=40 The "40" vs. the "4" shows the array parameter "adjustment". And (float) is similarly adjusted form 4 to 8, since it is actually passed as (double). What I don't understand is why the (short) and (char) parameters weren't adjusted to (int) for the same reason. Either they should all have been left alone (desirable) or they should all have been adjusted (correct). The current BSD 4.3 behaviour isn't even consistent with itself. Do other compilers get this adjustment right?