parameter adjustment (was double indirection)

Ray Butterworth rbutterworth at watmath.waterloo.edu
Tue Feb 16 00:42:25 AEST 1988


In article <2292 at umd5.umd.edu>, chris at 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 <N> of <T>', or even (belying what I
> said above) as `array of <T>', the parameter's type is NOT
> `array <N> of <T>'.  It is quietly adjusted by the compiler
> to `pointer to <T>'.
> 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 <stdio.h>

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?



More information about the Comp.lang.c mailing list