Author: Lex Loep
Date: 01:16:46 12/08/01
Altough a bit off topic I still post it as many here use the MSVC compiler.
This bug makes me feel a bit uneasy as this is just a simple constuction
and makes you wander how many more of these faults are in there.
Lex
When compiling the code fragment below with optimization for minimum size
the wrong code is produced.
The Good and Bad function should return the same result (0x11000)
but does not, Bad returns 0. Works fine in debug builds.
VS6SP5
// compilerbug.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <conio.h>
typedef unsigned long DWORD;
typedef unsigned char BYTE;
DWORD Good(BYTE P1,BYTE P2);
DWORD Bad(BYTE P1,BYTE P2);
int main(int argc, char* argv[])
{
BYTE Para1=0x10;
BYTE Para2=0;
DWORD ResultGood=Good(Para1,Para2);
DWORD ResultBad=Bad(Para1,Para2);
printf("Result good:%lx\n",ResultGood);
printf("Result bad:%lx\n",ResultBad);
_getch();
return 0;
}
DWORD Good(BYTE P1,BYTE P2)
{
if ( P1 == 0 )
return 0;
DWORD Result=((DWORD)P1<<8) | (P2);
if ( P2 == 0)
Result |= 0x10000;
return Result;
}
DWORD Bad(BYTE P1,BYTE P2)
{
DWORD Result=((DWORD)P1<<8) | (P2);
if (P1 ==0 )
return 0;
if ( P2 == 0)
Result |= 0x10000;
return Result;
}
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.