PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Selective Compiler Optimization

Does anyone know of a compiler directive that I can put around a specific section of my code that will tell the compiler NOT to optimize that particular block of code?

I have a situation where some of my code works when compiled for "Debug", but it doesn't work when compiled for "Release". I'm thinking that the compiler is optimizing-away some of my code. I'd like to tell it to "don't touch" this code.

Any ideas?

Thanks!
:D
Code:
#pragma optimize("", off)
// some code here
#pragma optimize("", on)


(It's documented in the eVC++ help in the #pragma section).
Thanks you, thank you, thank you! That's just what I needed. :D
refractor wrote:
Code:
#pragma optimize("", off)
// some code here
#pragma optimize("", on)


(It's documented in the eVC++ help in the #pragma section).


Hey Refractor you should start calling yourself rescuer or something ;)
angedelamort · 21 Sep 2004, 21:12 UTC
usually, when it's not working in release, it's because of a memory problem. But to be sure, you can always look at the assembly code to see if the compiler messed up ;)
Bap Dude:
I hope you are still following this thread. You *must* find out what your problem in release mode is. While I have had compilers screw up code through optimizations, the more likely explanation is that the code is *wrong* and just *happens* to work in debug mode. Bugs like that tend to go away for a little while and then spring back to life at just the wrong momement.

Always, always, always understand your code. If something is broken and you fix it... be sure to understand precisely *why* the fix worked. Prove it to yourself.

Even if this is just an optimization problem, find out why. If the compiler doesn't handle your code in one case, it is most likely to nip you again later. ie; it might just not like your style.
rcp:

Thanks for your suggestion. Yes, you are correct...I should try to understand the problem rather than looking for a "bandaid" solution.

My problem basically involves flags that are set before a function call. In the "debug" version, the flags are set correctly (initialized) prior to entering the function. In the "release" version, the flags are not. It's actually VERY simple code, so I can't imagine why the compiler has a problem with it. Of course, I've seen stranger things... :D
Are you sure the flags or not being set? Or are they being modified by a rouge piece of code after they are set?

Dan East
Debug builds tend to fill initialized data with zeroes. Make sure this is not your case.
andys · 06 Oct 2004, 13:36 UTC — Stupid debug filling with zeros
This bit me during some PocketPC development.

It really should poison the memory instead (ie, fill it with 0xDF or some scratch value), rather than setting it to zero, which is just annoying.
andys wrote:This bit me during some PocketPC development.

It really should poison the memory instead (ie, fill it with 0xDF or some scratch value), rather than setting it to zero, which is just annoying.


I think it will do that if you ask it to. I don't remember exactly how, but look up memory "CRT" functions in the help file. At least they exist on the desktop. I am pretty sure MFC uses them.
Haven't any of you guys ever seen 0xbaadf00d while debugging? :)

Dan East
Dan East wrote:Haven't any of you guys ever seen 0xbaadf00d while debugging? :)

Dan East


I am all too familiar with 0xdeadbeef.
Heh - I also use 0xdeadbeef.