Xref: utzoo comp.lang.c:9501 comp.sys.ibm.pc:14686 Path: utzoo!mnetor!uunet!husc6!uwvax!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: Turbo C bug with unsigned long integer. Message-ID: <11146@mimsy.UUCP> Date: 21 Apr 88 02:24:39 GMT References: <2658@im4u.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 23 Keywords: Turbo C, bug. In article <2658@im4u.UUCP> demelo@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@mimsy.umd.edu Path: uunet!mimsy!chris