So how are C++ and C# pointers done in IL ?

There are two kind of pointers in C#: managed and unmanaged. Wrapped in a fixed statement (just to tell the garbage collector to keep fixed references), C# pointers will behave like any native language pointer. This is not the first topic where I read that misconception that slices are a problem for IL. From .net 2.0 (9 years ago) there is the ArraySegment<T> type doing exactly what D slices do. Also, in C# arrays are implicitely convertible to pointers.

IIRC, the biggest incompatibility between D and .NET is that D pointers can point to the stack, to unmanaged (non-GC) memory or to managed (GC) memory, while simultaneously having unlimited lifetime. In .NET, arguments that are passed by reference can point to GC or non-GC memory, but pointers inside objects (classes or boxed structs) can only point to (1) non-GC non-stack memory OR (2) the beginning of a GC object. The key problem: a single pointer cannot be used for both purposes!

D pointers and ranges can point to stack, GC or non-GC memory, regardless of the location of the pointer or range itself. Also, D pointers can point to the interior of an object and not just the beginning, while .NET pointers, in general, cannot.

This doesn't make a D implementation for .NET impossible, but if you want to run arbitrary D code on .NET, I think it would have to run inefficiently because it would constantly have to work around limitations of .NET. I think doing D in .NET efficiently would require a specialized version of D, or something.

Note that plain old C++ can be used in .NET because C++ pointers can't point to GC memory without special .NET-specific types. Thus, old-fashioned C++ avoids problems related to the .NET garbage collector.

Anyway, I don't see any use for a D IL compiler, since probably the language syntax will look 90% like C#.

How is "looking" like C# relevant? D looks 90% like C++ too, and D is still better. Certainly D is more powerful than C# on the whole.

Reply via email to