473,387 Members | 1,481 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,387 software developers and data experts.

Bug Unmanaged -> Managed

Hi,

I've prepared a little example for my problem. Please take some time to
undestand it ;) OK, here it is:

class ClassA
{
public:
ClassA()
{
// Empty
}

ClassA( int value )
{
m_value = value;
}

int m_value;
};

class ClassB
{
public:
ClassB()
{
// Empty
}

ClassB( int value0, int value1 )
{
m_values[0] = ClassA( value0 );
m_values[1] = ClassA( value1 );
}

ClassA m_values[2];
};

void main()
{
ClassB test( 1, 2 );
}

So, there is a problem. Or let me say there is half a problem ;) When I
compile this code in a normal Win32-Console-Project, it works properly. But
when I compile this code in an Empty Project (.NET), there is a Bug. In the
constructor of ClassB, m_values[1] does not get any values assigned, while
m_values[0] gets the proper value of 1!
How can this happen - especially if it works in an unmanaged project?!

Greetings,
eXile.
Sep 15 '06 #1
3 1068
On Fri, 15 Sep 2006 08:24:02 -0700, eXile <eX***@discussions.microsoft.com>
wrote:
>Hi,

I've prepared a little example for my problem. Please take some time to
undestand it ;) OK, here it is:

class ClassA
{
public:
ClassA()
{
// Empty
}

ClassA( int value )
{
m_value = value;
}

int m_value;
};

class ClassB
{
public:
ClassB()
{
// Empty
}

ClassB( int value0, int value1 )
{
m_values[0] = ClassA( value0 );
m_values[1] = ClassA( value1 );
}

ClassA m_values[2];
};

void main()
{
ClassB test( 1, 2 );
}

So, there is a problem. Or let me say there is half a problem ;) When I
compile this code in a normal Win32-Console-Project, it works properly. But
when I compile this code in an Empty Project (.NET), there is a Bug. In the
constructor of ClassB, m_values[1] does not get any values assigned, while
m_values[0] gets the proper value of 1!
How can this happen - especially if it works in an unmanaged project?!
How are you determining this? Your program contains no observable behavior
(formally, I/O statements or writes to volatile variables), so the compiler
can reduce it all to nothing. You should also give the compiler version and
specify the options you use to compile this. When I add a printf statement
and compile with /clr and with and without /O2, I don't observe any problem
with VC.NET 2003 or 2005.

--
Doug Harrison
Visual C++ MVP
Sep 15 '06 #2
Ok I did a little research in the last hours.

First, I inserted some code to print the two values of ClassB to the console
(in both projects). Suprisingly, it printed both times "1 2", so the code
really works. However, something must be wrong either: The debugger says 1
and 0 in the .NET-Project, but 1 and 2 in the Win32-Console-Project.

So I changed my Win32-Console-Project this way:
Add /clr
Remove /RTC1
/Gm - /FD
/ZI -> /Zi
/MLd -> /MTd

Which lead to the same result like in the .NET-Project: The debugger states
1 and 0, the consoles prints 1 and 2.

So my conclusion is:
a) These Options deactivate some debugger-features. However, a debugger
should NOT give wrong information to the programmer (1 and 0 although its 1
and 2).
b) There is a bug in the Microsoft Visual Studio 2003 Debugger.

Thanks for the answer!

"Doug Harrison [MVP]" wrote:
On Fri, 15 Sep 2006 08:24:02 -0700, eXile <eX***@discussions.microsoft.com>
wrote:
How are you determining this? Your program contains no observable behavior
(formally, I/O statements or writes to volatile variables), so the compiler
can reduce it all to nothing. You should also give the compiler version and
specify the options you use to compile this. When I add a printf statement
and compile with /clr and with and without /O2, I don't observe any problem
with VC.NET 2003 or 2005.
Sep 15 '06 #3
On Fri, 15 Sep 2006 09:49:02 -0700, eXile <eX***@discussions.microsoft.com>
wrote:
>So my conclusion is:
a) These Options deactivate some debugger-features. However, a debugger
should NOT give wrong information to the programmer (1 and 0 although its 1
and 2).
b) There is a bug in the Microsoft Visual Studio 2003 Debugger.
This is why I believe that observing a problem only in the debugger is
tantamount to not observing it at all. Debuggers are for illuminating
problems you've already discovered, not for verifying correct operation of
your program.

--
Doug Harrison
Visual C++ MVP
Sep 15 '06 #4

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

Similar topics

3
by: BruceR | last post by:
Hello, I am currently trying to respond to custom messages sent via SendMessage/PostMessage from my unmanaged C++ dll in my C# application. I am responding to these types of messages by...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
5
by: Philippe Bertrand | last post by:
Using C#, I want to send a byte array to an unmanaged function with the minimum amount of copies. The array is input only and won't be modified (its copied on the unmanaged side). I'm currently...
2
by: Dave Griffin | last post by:
This is a followup to my question in doing unmanaged DLLs in .NET. I was able to create the DLL and the application was able to see it. So far so good. Now I need to make that unmanaged DLL read an...
2
by: J | last post by:
Compiling a straight C++ module under VC++ 7 would seem to autogen an 'IJW' type .NET module, even if the module has standard VC++ syntax. I'm assuming that the 'unmanaged' flag would have no...
0
by: DPR | last post by:
Hi, I've recognized that a mixed assembly with unmanaged exports and an unmanaged "DllMain" can't be unloaded from a (unmanaged) process, even if it's no longer needed and the (unmanaged)...
0
by: Chrisg | last post by:
Hi, I am using some unmanaged dll's written in C++ in vb.net. Is there a way to trap errors that the unmanaged code raises. My calls to the unmanaged world work and I have them in a Try...Catch...
7
by: Ragnar Agustsson | last post by:
Hi all I have been wandering about the best way to sandbox memory leaks in 3rd party libraries when using them from the .Net framework. I have a 3rd party library, written in C++, that leaks a...
2
by: eusebiu | last post by:
Hello... I am making a Sytem.IntPtr with Marshal.AllocHGlobal(int) (Allocates memory from the unmanaged memory of the process using GlobalAlloc - MSDN Definition for Marshal.AllocHGlobal) and after...
1
by: George2 | last post by:
Hello everyone, I think unmanaged resource means the resources (e.g. memory and file handler) which is used directly (new, FILE*) other than using a wrapper class (Resource Acquisition Is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...

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.