Message-ID: <000601be1232$a9d3b000$0f00a8c0@franc.intern.dresearch.de> From: "Michael Beck" To: Subject: Re: feature or bug? Date: Tue, 17 Nov 1998 15:00:41 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Reply-To: djgpp-workers AT delorie DOT com >Hi Workers! > >Just a small question: > >Let's say I have a 32-bit unsigned integer, and I want to clear it's >most significant bit. I wrote this code: > > (x*2)/2 > >And of course(?) it doesn't work. Is it a bug in gcc or a bug in me? > This seems to be a feature: Even if I did not optimize this code (gcc t.c), the compiler removes the *2/2 operation. For disabling the optimization, use the following construct: y = 2; x = (x*y)/2; This code work in all cases. However, why didn't you use x & 0x7FFFFFFF ??? -- Michael Beck, email: beck AT dresearch DOT de DResearch GmbH, D-10319 Berlin, Otto-Schmirgal-Strasse 3 Fon.: +49 (030) 515932 224 Fax.: +49 (030) 515932 299