[Mono-devel-list] C++/CLI and .NET 2.0

Michael Torrie torriem at chem.byu.edu
Thu Jul 1 23:41:15 EDT 2004


On Thu, 2004-07-01 at 21:14, Jonathan Pryor wrote:
> On Thu, 2004-07-01 at 21:21, Michael Torrie wrote:
> > If C++ programs are compiled to pure CLR apps, does that not mean that
> > the guaranteed destruction semantics of C++ will not apply?
> 
> Remember the C++/CLI mantra: It Just Works.

Looks like the concerns have been addressed.  I remember a presentation
a couple of years ago by microsoft on .NET and the CLI.  When one of our
C++ gurus brought up this stuff he just danced around the issue.  Since
then it seems it has been dealt with.  I will eagerly await trying some
of my C++ code on mono when that capability becomes available.  In the
meantime, C# is good (along with its java-like characteristics which I
am getting used to).

Michael


> 
> >From a C#-programmers view of C++/CLI, destructors are mapped to an
> IDisposable implementation, which are philosophically invoked from a
> finally block.  This is also bi-directional: classes containing an
> IDisposable implementation are seen as having destructors from within
> C++/CLI.  This can make for elegant code.
> 
> Consequently, the C++/CLI code:
> 
> 	String^ ReadFirstLineFromFile (String^ path)
> 	{
> 		StreamReader reader (path);
> 		return reader.ReadLine ();
> 	}
> 
> is identical to the C# code:
> 
> 	string ReadFirstLineFromFile (string path)
> 	{
> 		using (StreamReader reader = new StreamReader (path)) {
> 			return reader.ReadLine ();
> 		}
> 	}
> 
> This was taken from the MSDN Magazine article I referenced:
> 
> 	http://msdn.microsoft.com/msdnmag/issues/04/05/VisualC2005/default.aspx
> 
> C++/CLI also adds new syntax to override the finalizer: !<classname>:
> 
> 	public ref class Test {
> 	public:
> 		// Constructor
> 		Test ();
> 
> 		// Destructor: mapped to IDisposable.Dispose()
> 		~Test ();
> 
> 		// Finalizer: overrides Object.Finalize()
> 		!Test ();
> 	};
> 
> The short of it is that existing C++ code should Just Work, unchanged,
> within the CLI environment.
> 
> > If this is
> > the case then there are many C++ apps that would require some work if
> > they depend on this behavior (some of my C++ code depends on this).  I
> > believe this is one big reason why C++ on .NET will never be a huge
> > success.
> 
> I would suggest reading up on C++/CLI more before passing judgements
> like this. :-)
> 
> You might find Stan Lippman's blog to be helpful, as he's the primary
> author behind C++/CLI:
> 
> 	http://blogs.msdn.com/slippman/
> 
> > Would compiling C++ via whirl allow this somewhat critical c++
> > feature to work on .NET?
> 
> It would have to do the same thing (or similar) as C++/CLI.
> 
>  - Jon
> 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
-- 
Michael Torrie <torriem at chem.byu.edu>



More information about the Mono-devel-list mailing list