473,405 Members | 2,167 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.

Visual C++ Beta 2

When I compile the following code with the C++ compiler version
14.00.50215.44 (Microsoft Visual Studio 2005 beta 2) using the command line
'cl -W4 -clr:oldSyntax test.cpp' at run time I get a Null Reference Exception
due to the dynamic_cast. With the C++ compiler version 13.10.3077 from Visual
Studio 2003 using the command line 'cl -W4 -clr test.cpp' no such error is
generated.

#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;

public __gc class AttributesSample
{
public:
void Mymethod (int, [Out] String** str2m, String**)
{
*str2m = S"in Mymethod";
}
};

void PrintAttributes(Type* attribType, int iAttribValue)
{
if (attribType->IsEnum)
{
FieldInfo* fields[] =
attribType->GetFields(static_cast<BindingFlags>(BindingFlags: :Public |
BindingFlags::Static));
for (int i = 0; i < fields->Length; i++)
{
int fieldvalue = *dynamic_cast<Int32*>(fields[i]->GetValue(0));
//exception here
if ((fieldvalue & iAttribValue) == fieldvalue)
{
Console::WriteLine(fields[i]->Name);
}
}
}
}

int main()
{
Type* MyType = Type::GetType(S"AttributesSample");
MethodBase* Mymethodbase = MyType->GetMethod(S"Mymethod");
MethodAttributes Myattributes = Mymethodbase->Attributes;
PrintAttributes(__typeof(System::Reflection::Metho dAttributes), (int)
Myattributes);
return 0;
}

Is this a bug?
Nov 17 '05 #1
5 1270
Hi Paul!
When I compile the following code with the C++ compiler version
14.00.50215.44 (Microsoft Visual Studio 2005 beta 2) using the command line
'cl -W4 -clr:oldSyntax test.cpp' at run time I get a Null Reference Exception
due to the dynamic_cast. With the C++ compiler version 13.10.3077 from Visual
Studio 2003 using the command line 'cl -W4 -clr test.cpp' no such error is
generated.
It does not matter if you use the command-line or the IDE.
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;

public __gc class AttributesSample
{
public:
void Mymethod (int, [Out] String** str2m, String**)
{
*str2m = S"in Mymethod";
}
};

void PrintAttributes(Type* attribType, int iAttribValue)
{
if (attribType->IsEnum)
{
FieldInfo* fields[] =
attribType->GetFields(static_cast<BindingFlags>(BindingFlags: :Public |
BindingFlags::Static));
for (int i = 0; i < fields->Length; i++)
{
int fieldvalue = *dynamic_cast<Int32*>(fields[i]->GetValue(0));
//exception here
if ((fieldvalue & iAttribValue) == fieldvalue)
{
Console::WriteLine(fields[i]->Name);
}
}
}
}

int main()
{
Type* MyType = Type::GetType(S"AttributesSample");
MethodBase* Mymethodbase = MyType->GetMethod(S"Mymethod");
MethodAttributes Myattributes = Mymethodbase->Attributes;
PrintAttributes(__typeof(System::Reflection::Metho dAttributes), (int)
Myattributes);
return 0;
}

Is this a bug?


It seems to be!

The problem is that the VC2003 compiler generated the following IL-code:

<snipped>
obj1 = infoArray1[num1].GetValue(null);
int num1 = (int) obj1;
</snipped>

And the VC2005 B2 compiler /with /oldsyntax) generates:

<snipped>
obj1 = infoArray1[num1].GetValue(null);
int num1 = *(!(obj1 is int) ? 0 : ((int) obj1));
</snipped>
So please report a (detailed!) bug-report at:
http://lab.msdn.microsoft.com/productfeedback/

If you do not want to do this, please let me know, than I can do it for you.
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2
Is this a bug?
It seems to be!


But it looks like a bug in the VC2003 compiler!

Because "dynamic_cast" should excatly do what the VC2005 compiler is doing:
Check if the object has the correct type (or derived) and then cast it
to this type or return "null".
The problem is that the VC2003 compiler generated the following IL-code:

<snipped>
obj1 = infoArray1[num1].GetValue(null);
int num1 = (int) obj1;
</snipped>
This is wrong...
And the VC2005 B2 compiler /with /oldsyntax) generates:

<snipped>
obj1 = infoArray1[num1].GetValue(null);
int num1 = *(!(obj1 is int) ? 0 : ((int) obj1));
</snipped>


This is correct.
But it should be documented in the "breaking-changes"...
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #3
Hi Jochen,

Thanks for the reply. Although I found the problem first in my own code I
based it on the sample code (and reproduced it in the sample code as well).
The sample code is at:

http://msdn.microsoft.com/library/de...eldsTopic2.asp.

Therefore it looks like this sample code is wrong.

I have submitted a bug report anyway.

Regards,
Paul.

Nov 17 '05 #4
Hi Paul!
I have submitted a bug report anyway.


Can you please post the link, so other people can easily find it...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #5


"Jochen Kalmbach [MVP]" wrote:
Can you please post the link, so other people can easily find it...


The link is:

http://lab.msdn.microsoft.com/produc...3-a6abd826a899

Regards,
Paul

Nov 17 '05 #6

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

Similar topics

1
by: AJ | last post by:
Have I just wasted money on buying VS.NET Beta 2? I can run the start page but as soon as I try to load a solution file, I get an error within the Microsoft Development Environment as the Common...
2
by: Prasad | last post by:
Hello EveryBody, I am using cvs as my version control tool, I came accross CVS SCC plugin for Microsoft Visual Studio name "Jalindi Igloo" I plan to develop a tool like this, but have no idea to...
3
by: Benjamin.Nitschke | last post by:
Today I installed Microsoft Visual Studio 2005 Beta 2 from the Visual Studio Beta Experience Kit. After installing (which takes way to long) when I open Visual Studio 2005 I only get a message box...
1
by: Eric Sassaman [MS] | last post by:
Online Chat: Visual C++ 2005 Beta Join the Visual C++ team to discuss your questions and comments on the Beta release of Visual C++ 2005. Whether you are a first-time user of the Visual C++...
4
by: Jason Shohet | last post by:
I'm using Visual Studio, with ASP.NET. Is VSS on a separate CD. Also, is it possible to use the VSS beta (2005) with .NET if I'm not using the .NET beta. And finally, where do I get the VSS...
0
by: Maury | last post by:
I just downloaded .Net Framework Beta2 and Visual Web Developer Express Edition Beta and Visual C# Express Edition. I installed .Net Framework Beta2, then I installed Visual Web Developer...
0
by: Dr. Zharkov | last post by:
Hello. To see the graphics of technology DirectX 9.0 SDK Update - June 2005 in project Visual Basic, WindowsApplication1 from Visual Studio 2005 Beta 1, in file My Project, MyApplication.vb in a...
4
by: interwanderer | last post by:
something very odd... I have installed visual studio 2005 on my machine. I created a console application with visual basic 2005 or C#. I typed something in. tried to delete.. but i couldn't I...
1
by: micky | last post by:
i've download vs studio team suite but it look like beta 2 CTP versio such as folder structure.. there are msdn, visio, vs ,vss folder and to check version this iso file i opened setup.ini and...
5
by: nhmark64 | last post by:
Hi, What is the relationship between "Microsoft .NET Framework 3.5 – Beta 1" and "Visual Studio Code Name "Orcas" Beta 1"? Should I install 1 first than the other, or just 1? I need to start...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...

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.