> unsigned long var32;
> unsigned short var16;
> If I do this:
> var32= var16 * 60;
> I get a 16-bit multiply, not a 32-bit. This caused an overflow and a
> bug. doing this:
> var32= *(unsigned long)var16) * 60;
> solves that.
> But, I thought that there was automatic type promotion such that if the
> l-value is 32bits, then var16 would be promoted to 32bits prior to the
> multiply. Am I just wrong here? Is there any way to make SDCC do it
> that way? I'd rather waste some codespace/execution speed and never
> have an unanticipated overflow...
There is automatic type promotion, but only if one of
the operands is bigger than the other. The result has
nothing to do with it (this is standard C). Both var16
and 60 are of int size and thus no promotion. You have
to make either var16 (as you did) or 60 long (e.g. 60UL)
to get the result you want.