473,402 Members | 2,064 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,402 software developers and data experts.

MSVC++ 6.0 Complier optimization bug??

I wrote the following code into a console program in Visual C++6. If
you build a release build and select custom optimizations and select
'general optimizations' as the only optimization then you will end up
with incorrect results. Every line seems to be important, even the
unrelated bits. Any one have the time or inclination to try this out
for themselves and try to explain it?

#include "stdafx.h"
#include <string>

int main(int argc, char* argv[])
{
std::string s1; <- This is important

for(int i = 0; i<4; i++)
{
int shift = i*4; <- This is important
short temp = shift; <- This is important
printf("Generated %d\n", temp);
}

return 0;
while(1) <- This is important, take it out and the problem
disappears
{
}
}

The result of this program run with the specified optimizations is as
follows:
Generated 0
Generated 0
Generated 0
Generated 0

Note: This is (very) stripped down version of some production code I
had written that failed due to this odd bug. For now I plan to just
remove the optimizations until a proper fix can be determined. I hope
someone has some insight.

Apr 27 '06 #1
11 2250
Of course I meant COMPILER....

complier postings should go into alt.tools...anyway, the posting is
serious ;)

Apr 27 '06 #2

jryden wrote:
Of course I meant COMPILER....

complier postings should go into alt.tools...anyway, the posting is
serious ;)


I can't recreate the issue in 7.1

Apr 27 '06 #3
I compiled the following code using vc6sp5 and could not reproduce
the error.

cl -GX -Og test.cpp

#include <cstdio>
#include <string>

int main(int argc, char* argv[])
{
std::string s1; // <- This is important

for(int i = 0; i<4; i++)
{
int shift = i*4; // <- This is important
short temp = shift; // <- This is important
printf("Generated %d\n", temp);
}

return 0;

while(1) // <- This is important, take it out and the problem
disappears
{
}
}
Apr 27 '06 #4
jryden wrote:
I wrote the following code into a console program in Visual C++6. If
you build a release build and select custom optimizations and select
'general optimizations' as the only optimization then you will end up
with incorrect results. Every line seems to be important, even the
unrelated bits. Any one have the time or inclination to try this out
for themselves and try to explain it?
The optimizer of VC6 is buggy. I've seen similare unpleasant things.
#include "stdafx.h"
#include <string>

int main(int argc, char* argv[])
{
std::string s1; <- This is important

for(int i = 0; i<4; i++)
{
int shift = i*4; <- This is important
short temp = shift; <- This is important
printf("Generated %d\n", temp);
}

return 0;
while(1) <- This is important, take it out and the problem
disappears
{
}
}

The result of this program run with the specified optimizations is as
follows:
Generated 0
Generated 0
Generated 0
Generated 0

Note: This is (very) stripped down version of some production code I
had written that failed due to this odd bug. For now I plan to just
remove the optimizations until a proper fix can be determined. I hope
someone has some insight.


Try declaing 'temp' or 'shift' (or both) "volatile". And keep the
optimization. See what happens.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 27 '06 #5

jryden skrev:
I wrote the following code into a console program in Visual C++6. If
you build a release build and select custom optimizations and select
'general optimizations' as the only optimization then you will end up
with incorrect results.

[snip]
This is off topic but anyway.
Do not optimise to heavily with VC++ 6.0. So far as I remember /Os or
/Ot was okay, but more elaborate optimisations went bad.

/Peter

Apr 27 '06 #6
No I tried that myself...it is specific to VC6

Apr 28 '06 #7
Ah...I'm not sure that I'm running the latest service pack...I make
sure and then retest the code.

Thanks.

Apr 28 '06 #8
Hum...doesn't change anything. Good to cover all the bases though. I
think I must have actually been running SP because the installation ran
too quick. Anyone know where you tell what SP is installed in 6.0.
The help|about doesn't show any version numbers...

Apr 28 '06 #9
jryden wrote:
[...] Anyone know where you tell what SP is installed in
6.0. The help|about doesn't show any version numbers...


Please ask product-specific questions in the newsgroup dedicated
to your product. Example: microsoft.public.vc.ide_general.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 28 '06 #10
Um...okay...sorry, it just followed the thread of suggestions. Please
disregard the question.

In that vein I tried your suggestion to use 'volatile'. This solves
the problem despite that fact that these are not actually volatile
variables. This is a better solution than my current solution which is
to simply turn off the optimizations.

Since I have a viable solution please consider this thread closed and
thanks for the help.

James

Apr 28 '06 #11
jryden wrote:
No I tried that myself...it is specific to VC6


Tried what? See below.

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Apr 28 '06 #12

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
0
by: Leor Zolman | last post by:
The Intel C++ version of STLFilt (my STL Error Message Decryptor utility) has now been updated to support Intel C++ 8 (currently in Beta) along with version 7. All three MSVC libraries are...
21
by: Alf P. Steinbach | last post by:
Just because there seems to be a lack of post-standard _correct_ tutorials: <url: http://home.no.net/dubjai/win32cpptut/>. Disclaimer: written this evening so perhaps there are "bugs" in the...
5
by: Seven Kast USA | last post by:
Hi pelase explain me complier design of c and i need a small example complier design all phases in c programming . by KAST
2
by: qbin_wang | last post by:
Hi: now i want to download a free c complier which can be used in windows system.and i see many posts in the comp.lang.c,but i don't find the answer.who can tell me the true and correct website...
8
by: Chris Stankevitz | last post by:
I can't tell you how frusterated I and my coworkers are with "MSVC 7.1 .net 2003" (what am I supposed to call this thing anyway?). Compiling and linking take twice as long with "MSVC 7.1 .net...
2
by: Sen | last post by:
Hi All, I am using (Visual C++ 1.52 IDE )for my MFC Application Project. I am working on an existing code base where the no of lines is around 100,000, spread across different header and cpp...
11
by: neha | last post by:
Hi My question is : Would the expression *p++=c be disallowed by the complier. The answer given in the book is: No.Because here even though the vlue of p is acced twice it is used to modify...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.