[comp.sys.amiga] Type promotion in C.

mwm@eris.UUCP (02/14/87)

In article <1474@tekigm2.TEK.COM> phils@tekigm2.UUCP (Philip E Staub) writes:
>Finally, I found out (the hard way) while playing with the sample 
>printer drivers in the RKM that the Lattice compiler always seems to pass 
>32 bit parameters, even if the parameter type is declared as 'char' or
>'short'. The Manx compiler assumes that parameters which are declared as
>'char' or 'short' only take up 2 bytes on the stack.

This is all correct. In C, the smallest type for an expression is int.
Short/char types are promoted to int before the expression is
evaluated. Thus, parameters to functions are int or longer, even if
they are explicitly cast to shorter things. For Lattice, this means 32
bit parameters, for Manx (in 16 bit mode), this means 16 bit
parameters. This is yet another good reason for having a 16-bit int
mode on your 680[10]0 C compiler.

Back in the bad old days (of z80 C compilers), some of them offered
options which caused expressions to be evaluated in the type of the
longest variable/constant in the expression. Matt Dillon has already
posted a bug report on an early Lattice compiler caused by them
over-applying this principle.

	<mike



But I'll survive, no you won't catch me,		Mike Meyer
I'll resist the urge that is tempting me,		ucbvax!mwm
I'll avert my eyes, keep you off my knee,		mwm@berkeley.edu
But it feels so good when you talk to me.		mwm@ucbjade.BITNET