VC++ bug with code optimisation enabled?

  • Thread starter Thread starter richard sancenot
  • Start date Start date
R

richard sancenot

When calling the DrawSomething function, i get an access violation in release
mode.

This error happens when "Increase speed (/02)" is enabled
(Preferences->C/C++ -> Optimisation -> Increase speed (/O2) )

I use VS2005.

#ifdef DLL_EXPORT
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif

DLL_EXPORT short DrawSomething(CDC* DC)
{
CDC*pDC = (CDC*)DC;
//Access violation in release mode with /02!!
pDC->TextOut(0,0,_T("Hello world"));
return 1;
}

Thanks for helping
 
richard said:
When calling the DrawSomething function, i get an access violation in
release mode.

This error happens when "Increase speed (/02)" is enabled
(Preferences->C/C++ -> Optimisation -> Increase speed (/O2) )

I use VS2005.

#ifdef DLL_EXPORT
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif

DLL_EXPORT short DrawSomething(CDC* DC)
{
CDC*pDC = (CDC*)DC;
//Access violation in release mode with /02!!
pDC->TextOut(0,0,_T("Hello world"));
return 1;
}

You haven't supplied enough information for anyone to help you other than in
general terms. Most likely, the problem likes elsewhere in your code and is
a result of uninitialized data or an over-index array. See Joe Newcomer's
article "Surviving the Release Version" for guidance in tracking down
problems that appear only in release builds (or only with some optimization
levels).

http://www.flounder.com/debug_release.htm

It's possible that you are dealing with a real optimization bug as well -
they do happen. In that case, you need to produce a minimal complete
program, that demonstrates the problem, along with compiler version
information and the complete set of compiler options that were used to
compile the code. Only then can someone else weigh in on whether you're
really looking at an optimization bug.

-cd
 
richard said:
When calling the DrawSomething function, i get an access violation in release
mode.

This error happens when "Increase speed (/02)" is enabled
(Preferences->C/C++ -> Optimisation -> Increase speed (/O2) )

I use VS2005.

you need to keep function definition in a .cpp file (the one used to
build your .dll); header should contain nothing else but declaration.
Otherwise inlining may kick in, which beats the purpose of using dynamic
library


B.
 
Back
Top