query: argument passing on UNIX PC, VAX, et al

Andrew Koenig ark at alice.UucP
Sat May 17 14:25:45 AEST 1986


> I am interested in the precision used by various C compilers when
> passing arguments on the stack to a called routine.  For example:
>
>    some_routine_or_main()
>    {
>	char	a,b;
>
>	foo(a,b)
>    }
>
>    foo (a,b)
>    long a,b;
>
>    {
>	printf("%#lx\t%#lx\n", a, b);
>    }
>
> I tried a program similar to the above on a vax and a UNIX PC
> and in both cases the values of 'a' and 'b' were correctly
> passed.  Given that a long on both machines is 32 bits and a char
> is 8 bits, from this I assumed that both compilers are expanding
> 'a' and 'b' to 32 bits before putting them on the stack.  I might
> have expected this for the vax, but not for the UNIX PC (68000
> based).

The definition of C is that char or short arguments are expanded
to ints.  Both the VAX and UNIX PC (and the 3B machines, for that
matter) support 32-bit ints.  Since subscripts are ints rather than
longs, a machine that implements only 16-bit ints has a rather hard
time dealing with arrays with more than 32767 elements.  This
is, of course, often the case on little machines like PDP-11 or 8086.



More information about the Comp.lang.c mailing list