473,399 Members | 4,254 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,399 software developers and data experts.

VC++ bug with code optimisation enabled?

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
Sep 25 '08 #1
2 1459
richard sancenot wrote:
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
Sep 25 '08 #2
richard sancenot wrote:
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.

#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;
}
Sep 27 '08 #3

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

Similar topics

3
by: Ryan | last post by:
My project uses the /ORDER specifier to order functions as specified in file containing the decorated names of packaged functions (COMDATs). I am in the process of upgrading from VC6 to VC.NET 2003....
6
by: Ben Terry | last post by:
Hello, I have a VS 2003.NET solution which consists of four c++ unmanaged legacy projects. I am adding a new project to the solution which will be in c#. What do I need to do to my c++ projects...
10
by: PufferFish | last post by:
Hi folks, I hope that this is the correct group for these things, apologies if not. I've got a strange compiler error. It appears to be similar to the issue described in knowledgebase...
8
by: Greg Stoch | last post by:
Hi, I'm newcomer to Microsoft product (VS.net 7.0, C++) and need to understand, why the binary code obtained using VC++ compiler is so huge as compared to the code by Borland C++ 5.02 (the same...
1
by: John | last post by:
I have a VB6 ActiveX dll and it's called from a VC++ app. How can I debug the dll through the app? Please help. Thanks.
10
by: Diego Martins | last post by:
I just discovered a serious issue when compiling code using auto_ptr<> and VC 8.0 consider some sort of create() function blahblah * create() { return new blahblah; } and a pretty auto_ptr
3
by: starffly | last post by:
I overloaded operator+ in a class, and I want to invoke this operator in inline assemble like this: _asm call operator+ but it cannot be complied OK. compiler says there are some illegalI...
3
by: =?Utf-8?B?Q2luZHk=?= | last post by:
Hi all, I am trying to connect to a electromyograph machine for my thesis project, and I have a VB DDE client whose DDE functionality I want to convert to VC++. However I can't make my VC++...
5
by: cory.laflin | last post by:
Hi. I have what I believe to be a very simple task I'm trying to accomplish in VC++ 2005 and I simply can't make it work. I have a good working knowledge of C, a basic-to-middling knowledge of...
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?
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:
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.