Jesse, > 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. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user