multi-dimensional array differences in MCpp & C#
Author |
Message |
Dr Ev #1 / 6
|
multi-dimensional array differences in MCpp & C#
Hello. I hope someone can help me understand what IL DASM is trying to tell me about the 2 assemblies I have. I have a managed C++ class that defines a number of methods with signatures similar to this: virtual bool TwoDimBoolean(bool param0 __gc [,] ) __gc [,]; Then, in another assembly, a C# class derives from and overrides these like this: public override bool [,] TwoDimBoolean( bool [,] a ){} When I look in the IL DASM at the methods of each class in their seperate assemblies, the signatures are different. For the managed C++ class it's: TwoDimBoolean : bool[,](bool[,]) But for the C# generated assembly it's: TwoDimBoolean : bool[0...,0...](bool[0...,0...]) Can anyone tell me what IL DASM is trying to tell me? Thanks a bunch!
|
Sat, 08 Jan 2005 11:50:28 GMT |
|
|
Sean Gie #2 / 6
|
multi-dimensional array differences in MCpp & C#
I have never used multidimensional arrays myself, but it looks like the C# version is explicitly 0-based while the MC++ version does not have an explicit lower bound. I find it strange that System.Array has a method to get the lower-bound of any array dimension while there is no documented way for it to be anything other than zero. Maybe the CLR provides for non-zero based arrays and the C# compiler is just more explicit with the code it generates. -Sean
Quote: > Hello. I hope someone can help me understand what IL DASM is trying to > tell me about the 2 assemblies I have. > I have a managed C++ class that defines a number of methods with > signatures similar to this: > virtual bool TwoDimBoolean(bool param0 __gc [,] ) __gc [,]; > Then, in another assembly, a C# class derives from and overrides these > like this: > public override bool [,] TwoDimBoolean( bool [,] a ){} > When I look in the IL DASM at the methods of each class in their > seperate assemblies, the signatures are different. For the managed > C++ class it's: > TwoDimBoolean : bool[,](bool[,]) > But for the C# generated assembly it's: > TwoDimBoolean : bool[0...,0...](bool[0...,0...]) > Can anyone tell me what IL DASM is trying to tell me? > Thanks a bunch!
|
Mon, 10 Jan 2005 00:30:22 GMT |
|
|
Ronald Laeremans [MSFT #3 / 6
|
multi-dimensional array differences in MCpp & C#
The C# compiler forces the arrays bounds to be zero (only zero based arrays are CLS compliant). The C++ compiler does not. We might change our compiler's behavior in a future version. Have you found any place where this breaks a practical scenario? Ronald Laeremans Visual C++ compiler and libraries team
Quote: > I have never used multidimensional arrays myself, but it looks like the C# > version is explicitly 0-based while the MC++ version does not have an > explicit lower bound. I find it strange that System.Array has a method to > get the lower-bound of any array dimension while there is no documented way > for it to be anything other than zero. > Maybe the CLR provides for non-zero based arrays and the C# compiler is just > more explicit with the code it generates. > -Sean
> > Hello. I hope someone can help me understand what IL DASM is trying to > > tell me about the 2 assemblies I have. > > I have a managed C++ class that defines a number of methods with > > signatures similar to this: > > virtual bool TwoDimBoolean(bool param0 __gc [,] ) __gc [,]; > > Then, in another assembly, a C# class derives from and overrides these > > like this: > > public override bool [,] TwoDimBoolean( bool [,] a ){} > > When I look in the IL DASM at the methods of each class in their > > seperate assemblies, the signatures are different. For the managed > > C++ class it's: > > TwoDimBoolean : bool[,](bool[,]) > > But for the C# generated assembly it's: > > TwoDimBoolean : bool[0...,0...](bool[0...,0...]) > > Can anyone tell me what IL DASM is trying to tell me? > > Thanks a bunch!
|
Mon, 10 Jan 2005 07:32:23 GMT |
|
|
Tomas Restrepo [MVP #4 / 6
|
multi-dimensional array differences in MCpp & C#
Sean, Quote: > I have never used multidimensional arrays myself, but it looks like the C# > version is explicitly 0-based while the MC++ version does not have an > explicit lower bound. I find it strange that System.Array has a method to > get the lower-bound of any array dimension while there is no documented way > for it to be anything other than zero.
AFAIK, the runtime does indeed fully support non-zero lower-bounds for arrays... it's just that none of the popular MS languages take advantage of it... -- Tomas Restrepo
|
Mon, 10 Jan 2005 07:52:05 GMT |
|
|
Dr Ev #5 / 6
|
multi-dimensional array differences in MCpp & C#
Sounds plausable. Learning IL DASM would probably help. Thanks for the insight. Evil Doctor. Quote:
> I have never used multidimensional arrays myself, but it looks like the C# > version is explicitly 0-based while the MC++ version does not have an > explicit lower bound. I find it strange that System.Array has a method to > get the lower-bound of any array dimension while there is no documented way > for it to be anything other than zero. > Maybe the CLR provides for non-zero based arrays and the C# compiler is just > more explicit with the code it generates. > -Sean
> > Hello. I hope someone can help me understand what IL DASM is trying to > > tell me about the 2 assemblies I have. > > I have a managed C++ class that defines a number of methods with > > signatures similar to this: > > virtual bool TwoDimBoolean(bool param0 __gc [,] ) __gc [,]; > > Then, in another assembly, a C# class derives from and overrides these > > like this: > > public override bool [,] TwoDimBoolean( bool [,] a ){} > > When I look in the IL DASM at the methods of each class in their > > seperate assemblies, the signatures are different. For the managed > > C++ class it's: > > TwoDimBoolean : bool[,](bool[,]) > > But for the C# generated assembly it's: > > TwoDimBoolean : bool[0...,0...](bool[0...,0...]) > > Can anyone tell me what IL DASM is trying to tell me? > > Thanks a bunch!
|
Mon, 10 Jan 2005 10:31:03 GMT |
|
|
Jonathan Caves [MSFT #6 / 6
|
multi-dimensional array differences in MCpp & C#
This behavior is due a bug in the MC++ compiler. It will be fixed in a future release. -- Jonathan Caves Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights.
Quote: > Thanks for your feedback. The ILDASM report differences in the arrays > caught my attention while I was looking into a runtime problem with 2 > classes. I finally have been able to re-produce the problem in a > small enough example to post here. Incidently, ILDASM doesn't report > differences in the arrays with this small sample, but that was really > never the problem... I only thought at the time it was a clue. > So here's the very interesting situation: C++ W/Managed Extensions > class w/2 pure methods: > namespace arrayfun{ > public __gc class MCppArrayBase { > public: > MCppArrayBase(); > virtual bool OneDimBoolean(bool param0 __gc [] ) __gc [] = 0; > virtual bool TwoDimBoolean(bool param0 __gc [,] ) __gc [,] = 0; > }; > A C# class derives from it: > public class CSharpArrays : arrayfun.MCppArrayBase { > public CSharpArrays(){ > } > public override bool [] OneDimBoolean( bool [] a ){ > return a; > } > public override bool [,] TwoDimBoolean( bool [,] a ){ > return a; > } > } > When the CLR trys to create an instance of CSharpArrays it throws an > exception: > System.TypeLoadException: Method TwoDimBoolean in type > ArrayTest.CSharpArrays fr > om assembly TwoDimBoolean does not have an implementation. > If I change the TwoDimBoolean to be non-pure virtual it loads ok... > but the CLR never complains about pure virtual single dim array? > How come? > More Complete code follows: > C++ base: > #pragma once > using namespace System; > #define PUREVIRTUAL > namespace arrayfun{ > public __gc class MCppArrayBase { > public: > MCppArrayBase(); > virtual bool OneDimBoolean(bool param0 __gc [] ) __gc [] = 0; > #ifdef PUREVIRTUAL > virtual bool TwoDimBoolean(bool param0 __gc [,] ) __gc [,] = 0; > #else > virtual bool TwoDimBoolean(bool param0 __gc [,] ) __gc [,]; > #endif > }; > #include "stdafx.h" > #include "MCppArrayBase.h" > namespace arrayfun{ > MCppArrayBase::MCppArrayBase(){ > } > #if 0 // this class with this single dim array always loads ok if not > defined > bool MCppArrayBase::OneDimBoolean(bool param0 __gc [] ) __gc []{ > return param0; > } > #endif > // here's the problem. CSharp derived class only loads if this one is > defined > #ifndef PUREVIRTUAL > bool MCppArrayBase::TwoDimBoolean(bool param0 __gc [,] ) __gc [,]{ > return param0; > } > #endif > } > C Sharp: > using System; > namespace ArrayTest{ > public class CSharpArrays : arrayfun.MCppArrayBase { > public CSharpArrays() { > } > public override bool [] OneDimBoolean( bool [] a ){ > return a; > } > public override bool [,] TwoDimBoolean( bool [,] a ) { > return a; > } > } > class Class1 { > [STAThread] > static void Main(string[] args) { > Class1 c1 = new Class1(); > try { > c1.testCallbacks(); > } > catch ( System.Exception e ) { > System.Console.WriteLine(e); > } > } > public Class1() { > } > public void testCallbacks() { > CSharpArrays whoops = new CSharpArrays(); > Console.WriteLine("ae.excersize returned"); > } > } > }
|
Mon, 31 Jan 2005 01:13:17 GMT |
|
|
|