Turbo C bug with unsigned long integer.
Chris Torek
chris at mimsy.UUCP
Thu Apr 21 12:24:39 AEST 1988
In article <2658 at im4u.UUCP> demelo at im4u.UUCP (Julio De Melo) writes:
> unsigned long variable;
> ...
> variable = 1 << num_shift;
> where : num_shift < 32;
> The problem is that if num_shift is higher than 14, I get
>(I suppose so) unnexpected results.
This is not a bug. To get what you want, you must shift an unsigned
long 1, not an ordinary integer 1. The result of `1 << num_shift'
is determined by the type of the left-hand operand of `<<', namely
`1'; the shift is thus done in integer precision. Try
variable = 1UL << num_shift;
or
variable = (unsigned long)1 << num_shift;
(the former may not exist in various compilers).
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list