473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

optimize Pentium 4 and above bug!?

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)

Nov 17 '05 #1
2 1114
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.

Ludde wrote:
I beleave I have found a bug in the C++ compiler of Visual Studio 2003

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 /Zi
class Test
{
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);
}

Nov 17 '05 #2
dfg
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
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Cavell | last post by:
Hi, I wish to write an algorithm in C++. My intention is to run it on a Mac G4, however it would be nice to have the same program compile and run on a Pentium 4. The program will have to do...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
5
by: Subrahmanyam Arya | last post by:
Hi Folks , I am trying to solve the problem of reading the numbers correctly from a serial line into an intel pentium processor machine . I am reading 1 byte and 2byte data both positive...
11
by: Michael B. | last post by:
I'm still learning C so I've written a simple app which lets you make a contact list (stored as a linked list of structs), write it to a file, and read it back. It works fine, but I notice in my...
0
by: Daniel | last post by:
Hi there, I recently came across an interesting option when right clicking on a project (Right click on the project -> properties -> Configuration Properties ->Build -> Optimize) There is an...
6
by: arkam | last post by:
Hi, I wanted to test and compare performances of Webservices / Assemblies and Remoting in dotnet using aspnet clients ! I performed a lot of tests and there are the results : (less is better)...
3
by: Sonnich | last post by:
While trying to shorten my files, I tried optimize table - later I found that I need: mysqlcheck -u root -p[password[ --all-databases --analyze --optimize (thanks to Markus Popp). But it...
4
by: Jean-Claude | last post by:
Hi, which is the faster query ? (of course, in my case the real queries are more complex) 1/ select * from file1 a join file2 b on b.key=a.key where b.data=123 and b.name='TEST'
4
by: George2 | last post by:
Hello everyone, Why visual studio does not optimize constructor in this case? I do not understand what the MSDN mentioned, if use different named object, compiler can not optimize. Why? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.