Sender: nate AT cartsys DOT com Message-ID: <35A66020.DDA10500@cartsys.com> Date: Fri, 10 Jul 1998 11:40:32 -0700 From: Nate Eldredge MIME-Version: 1.0 To: Horst Kraemer CC: djgpp AT delorie DOT com Subject: Re: Infinite loop??? References: <35A3D8C3 DOT 208E6D23 AT cyberdude DOT com> <35a3fc6d DOT 35890095 AT news DOT snafu DOT de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Horst Kraemer wrote: > > On Wed, 08 Jul 1998 22:38:27 +0200, dns AT cyberdude DOT com wrote: > > >I use the following code: > >unsigned short s=1; > >unsigned int t=1; > >while ((s< > t++; } > > You just discovered a case of undefined behaviour. If you really need to know the number of bits in a `short', you could do: unsigned short s = 1; unsigned int t = 1; while ((s <<= 1) != 0) t++; It's theoretically possible that some machines might barf when `s' overflows, but I don't know of any that do. -- Nate Eldredge nate AT cartsys DOT com