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

/Od compiler option problem

Hi

I am running a project in eVC 4.0 and I have been running into a bug
that only appears in the release build of the project. I eventually
found out that when I had the compiler option /Od set the project would
work properly but when it was not set the bug would appear.
I looked for /Od in the MSDN library but it didn't provide much help.
Can anyone help me with what in my code that could lead to this? I.e
what should I look for in my project to fix this bug?

Is it ok to have this option set in a release build? What are the
consequences of that?

Thanks for all your help.
Best regards.
/Babak

Nov 17 '05 #1
3 1331
babak wrote:
Hi

I am running a project in eVC 4.0 and I have been running into a bug
that only appears in the release build of the project. I eventually
found out that when I had the compiler option /Od set the project
would work properly but when it was not set the bug would appear.
I looked for /Od in the MSDN library but it didn't provide much help.
Can anyone help me with what in my code that could lead to this? I.e
what should I look for in my project to fix this bug?

Is it ok to have this option set in a release build? What are the
consequences of that?


/Od disables optimization.

If your code depends on /Od, then there are a couple possibilities:

1. There's a compiler bug in the optimizer (not unheard of).
2. Your code is relying on undefined behavior that happens to be different
when compiled with /Od (far more common).

You need to try to narrow down just exactly how/where your code fails when
compiled with optimizations. If you can reduce it down to a small,
complete, postable program that exhibits different behavior with and without
/Od, then if you post that code here, someone will no doubt be able to
determine if it's a compiler bug or if you're relying on undefined behavior.

These things can be tough to find since there are so many ways to invoke
undefined behavior in C++. A very common cause is reliance on initial
values of uninitialized variables, but there are many others.

-cd
Nov 17 '05 #2
"babak" <ba*********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I am running a project in eVC 4.0 and I have been running into a bug
that only appears in the release build of the project. I eventually
found out that when I had the compiler option /Od set the project would
work properly but when it was not set the bug would appear.
I looked for /Od in the MSDN library but it didn't provide much help.
Can anyone help me with what in my code that could lead to this? I.e
what should I look for in my project to fix this bug?
/Od means "disable the optimizing compiler". With optimizations disabled,
the job of the compiler is simply (well, ok not simply <g>) to translate
source code to object code. It is important to disable optimizations while
debugging to keep the compiler from storing variables in registers, moving
non-varying quantities outside of loops, reordering statements etc. If it
did any of that it would be almost impossible to debug.

When optimizations are enabled the compiler may do those things and more. In
general, that's a good thing as it speeds up execution. The downside is that
it may reveal latent bugs or introduce its own.
Is it ok to have this option set in a release build? What are the
consequences of that?


Technically yes. Practically no. That's because you may not be pleased at
the resulting execution speed with optimizations disabled.

I would first try to replace Od by O1 and then O2. If either works I'd
declare success and call it a day. If neither does you may want to try
enabling optimizations on a file-by-file basis. If that works, then you
enable optimizations one at a time until it breaks. At that point you can
declare success again or you can try to find the cause.

To do that add

#pragma optimize("", off)

at the top of a source file

and

#pragma optimize("", on)

Then what you do is successfully shrink the size of the non-optimized region
(moving off lower down the file, moving on higher up) until you find the
stretch of code where optimization fails.

Then post that _short_ stretch here and someone will likely be able to
suggest a work-around.

Regards,
Will
Nov 17 '05 #3

William DePalo [MVP VC++] skrev:
"babak" <ba*********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I am running a project in eVC 4.0 and I have been running into a bug
that only appears in the release build of the project. I eventually
found out that when I had the compiler option /Od set the project would
work properly but when it was not set the bug would appear.
I looked for /Od in the MSDN library but it didn't provide much help.
Can anyone help me with what in my code that could lead to this? I.e
what should I look for in my project to fix this bug?


/Od means "disable the optimizing compiler". With optimizations disabled,
the job of the compiler is simply (well, ok not simply <g>) to translate
source code to object code. It is important to disable optimizations while
debugging to keep the compiler from storing variables in registers, moving
non-varying quantities outside of loops, reordering statements etc. If it
did any of that it would be almost impossible to debug.

When optimizations are enabled the compiler may do those things and more. In
general, that's a good thing as it speeds up execution. The downside is that
it may reveal latent bugs or introduce its own.
Is it ok to have this option set in a release build? What are the
consequences of that?


Technically yes. Practically no. That's because you may not be pleased at
the resulting execution speed with optimizations disabled.

I would first try to replace Od by O1 and then O2. If either works I'd
declare success and call it a day. If neither does you may want to try
enabling optimizations on a file-by-file basis. If that works, then you
enable optimizations one at a time until it breaks. At that point you can
declare success again or you can try to find the cause.

To do that add

#pragma optimize("", off)

at the top of a source file

and

#pragma optimize("", on)

Then what you do is successfully shrink the size of the non-optimized region
(moving off lower down the file, moving on higher up) until you find the
stretch of code where optimization fails.

Then post that _short_ stretch here and someone will likely be able to
suggest a work-around.

Regards,
Will

William and Carl
Thanks a lot for your help. I will try your suggestions and get back if
the problem still exists.

Regards.
/Babak

Nov 17 '05 #4

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

Similar topics

188
by: Ilias Lazaridis | last post by:
I'm a newcomer to python: - E01: The Java Failure - May Python Helps? http://groups-beta.google.com/group/comp.lang.python/msg/75f0c5c35374f553 - I've download (as suggested) the python...
1
by: Param | last post by:
Hi , I have faced a strange problem. I have a code something like this... while(!a) { if( condition ) { continue; // 1 } try {
7
by: Matthew Del Buono | last post by:
Don't try to solve the problem. I've found a way -- around or fixing it. I'm just curious as to whether this is Microsoft's problem in their compiler or if there's a standard saying this is to be...
19
by: David W | last post by:
float nanometers(long pm) { return pm / 1000.0f; } void f() { if(nanometers(309311L) == nanometers(309311L)) { // do something }
4
by: sqlguy | last post by:
Why do we have to contact MS for a problem that has been with this compiler from at least the beta of VS 20005. I am so sick and tired of the 30 - 40 clicks it takes to dismiss VS when there is a...
3
by: Rene | last post by:
Hello to all! For a long time I have been "fighting" a problem compiling an OpenGL program which uses GLUT. First I have put a question in a Watcom group (I want to use this compiler) to which I...
27
by: Dave | last post by:
I'm having a hard time tying to build gcc 4.3.1 on Solaris using the GNU compilers. I then decided to try to use Sun's compiler. The Sun Studio 12 compiler reports the following code, which is in...
2
by: =?Utf-8?B?TUNN?= | last post by:
I am using the compiler: Microsoft.VisualBasic.VBCodeProvider What are the different options I can specify using <providerOption>? So far I have: <system.codedom> <compilers> <compiler...
1
by: Alex Vinokur | last post by:
Hi, I have compilation problem on SUN CC compiler with template while using option -m64 (64-bit addressing model). No problem while using option -m32 (32-bit addressing model) $ CC -V CC:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.