Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

optimize Pentium 4 and above bug!?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ludde - 01 May 2004 07:11 GMT
I beleave I have found a bug in the C++ compiler of Visual Studio 200

The correct output for the code below is "Color is: 99b2cce5" but if I turn on the Pentium 4 and above (/G7) options
I get the follow result "Color is: 80000000" which is completly wrong

I found this bug when upgrading from visual studio 6.0 and my colors turned black! :

/O2 /Ot /G7 /I "../../DevelopmentSystem" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /MD /Fp".\Release/Europe.pch" /Fo"Release/" /Fd"Release/vc70.pdb" /FR"Release/" /W3 /nologo /c /Wp64 /Z

class Tes

public
 float a, r, g, b

 uint get(
 
   uint c  = a*255; c<<=8
   c += r*255; c<<=8
   c += g*255; c<<=8
   c += b*255

   return c
 
}

void main(int argc, const char **argv

 Test test
 test.a = .6
 test.r = .7
 test.g = .8
 test.b = .9

 uint c = test.get()

 printf("%x\n", c)
Sean Cavanaugh - 01 May 2004 11:25 GMT
The variable 'c' is being converted to a float during the += operation
and causing you some rounding errors on the conversion back to int.
Cast the expressions to (int) i.e.

c += r*255;

is equivalent to

c = c + r * 255;

which means the entire expression is promoted to a float type becuase of
r's type.

c += (unsigned char)(r*255);

I would probably recommend going the extra mile and use |= operator,
which will also catch any accidental use of float in this case as well.

> I beleave I have found a bug in the C++ compiler of Visual Studio 2003
>
[quoted text clipped - 33 lines]
>   printf("%x\n", c);
> }
dfg@fgfg.no - 01 May 2004 19:47 GMT
I agree with your point about rounding errors and I will change my code
accordingly, but this still does not explain
why I get a calculation error when turing on optimizing for pentium 4.

Ludde

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.