|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
CLR and accessible featuresHi all,
I was reading about MSIL and i came to know that there are some features of CLR that can be only accessed by programming in IL. I want to know what are these features which cannot be accessed by languages like c# or vb.net Thanks pradeep_tp "pradeep_TP" <pradee***@discussions.microsoft.com> wrote in message What exactly do you mean with "features of the CLR", MSIL allows you to do news:1F7FC440-E89A-4487-9E26-FA8AFF442214@microsoft.com... | Hi all, | | I was reading about MSIL and i came to know that there are some features of | CLR that can be only accessed by programming in IL. I want to know what are | these features which cannot be accessed by languages like c# or vb.net | | Thanks | pradeep_tp things which aren't possible/allowed to do in higher level languages, but as far as the CLR goes there is nothing that IL does what can't be done in C# for instance. Willy. Hi willy
By saying "features of CLR" , I mean CLR's facilties. As you have mentioned, what are those things which are allowed/possisble only through MSIL. thanks pradeep_tp Show quote "Willy Denoyette [MVP]" wrote: > > "pradeep_TP" <pradee***@discussions.microsoft.com> wrote in message > news:1F7FC440-E89A-4487-9E26-FA8AFF442214@microsoft.com... > | Hi all, > | > | I was reading about MSIL and i came to know that there are some features > of > | CLR that can be only accessed by programming in IL. I want to know what > are > | these features which cannot be accessed by languages like c# or vb.net > | > | Thanks > | pradeep_tp > > What exactly do you mean with "features of the CLR", MSIL allows you to do > things which aren't possible/allowed to do in higher level languages, but as > far as the CLR goes there is nothing that IL does what can't be done in C# > for instance. > > Willy. > > > One thing that can be done using IL but cannot be done using C# or
VB.NET is that the access modifier protected internal. The protected internal in C# or VB.NET is an "OR" operator that is it is either protected or internal. In IL it possible to declare "protected or internal" and "protected and internal". "Naveen" <naveensrinivasan.nav***@gmail.com> wrote in message However, it can be done in managed C++.news:1137246211.285671.322840@g44g2000cwa.googlegroups.com... | One thing that can be done using IL but cannot be done using C# or | VB.NET is that the access modifier protected internal. The protected | internal in C# or VB.NET is an "OR" operator that is it is either | protected or internal. In IL it possible to declare "protected or | internal" and "protected and internal". | Willy. Yes, I know it can be done in Managed C++. But the intial question was
what can be done in IL that cannot be done in C# or VB.NET. "Naveen" <naveensrinivasan.nav***@gmail.com> wrote in message Ok, some nitpickng maybe, but the OP said "...by languages like C# and news:1137251127.667583.67570@f14g2000cwb.googlegroups.com... | Yes, I know it can be done in Managed C++. But the intial question was | what can be done in IL that cannot be done in C# or VB.NET. | VB.NET....", which IMO has a broader scope than "in C# and VB.NET". But I was expecting this when I replied, that's why I said in my other reply that it's hard to tell what can be done in IL that can't be done in higher level languages. The point is, if you realy need something that can't be done in your language of choice, are you going to do it in IL when you can do it in another higher level language? Not an easy question to answer either. Willy. Oh, I see, but I'm afraid I can't answer this question because I don't know
all languages that target the CLR. If I restrict myself to C#, VB.NET and managed C++, all I can come up with is: - managed exports, that is the possibility to expose managed functions to unmanaged callers. - overloads of methods with covariant return types Willy. Show quote "pradeep_TP" <pradee***@discussions.microsoft.com> wrote in message news:CF8B5B0D-0E9E-44E7-94E6-EC1A20A3FF4E@microsoft.com... | Hi willy | | By saying "features of CLR" , I mean CLR's facilties. As you have | mentioned, what are those things which are allowed/possisble only through | MSIL. | | thanks | pradeep_tp | | "Willy Denoyette [MVP]" wrote: | | > | > "pradeep_TP" <pradee***@discussions.microsoft.com> wrote in message | > news:1F7FC440-E89A-4487-9E26-FA8AFF442214@microsoft.com... | > | Hi all, | > | | > | I was reading about MSIL and i came to know that there are some features | > of | > | CLR that can be only accessed by programming in IL. I want to know what | > are | > | these features which cannot be accessed by languages like c# or vb.net | > | | > | Thanks | > | pradeep_tp | > | > What exactly do you mean with "features of the CLR", MSIL allows you to do | > things which aren't possible/allowed to do in higher level languages, but as | > far as the CLR goes there is nothing that IL does what can't be done in C# | > for instance. | > | > Willy. | > | > | > Willy Denoyette [MVP] <willy.denoye***@telenet.be> wrote:
> Oh, I see, but I'm afraid I can't answer this question because I don't know Do any of the languages allow you to modify a boxed value in place? For > all languages that target the CLR. > If I restrict myself to C#, VB.NET and managed C++, all I can come up with > is: > - managed exports, that is the possibility to expose managed functions to > unmanaged callers. > - overloads of methods with covariant return types instance, if I had a struct: public struct Foo { public int x; } and put that into an ArrayList, in C# I certainly wouldn't be able to modify the value in the list - I'd have to overwrite it with a new boxed value after unboxing and modifying the other one, if you see what I mean. My guess is that it's available in C++, but it doesn't hurt to know these things... -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
Show quote
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message Don't know about other languages, but AFAIK the managed C++ language has no news:MPG.1e332a3085fa441498ccdf@msnews.microsoft.com... | Willy Denoyette [MVP] <willy.denoye***@telenet.be> wrote: | > Oh, I see, but I'm afraid I can't answer this question because I don't know | > all languages that target the CLR. | > If I restrict myself to C#, VB.NET and managed C++, all I can come up with | > is: | > - managed exports, that is the possibility to expose managed functions to | > unmanaged callers. | > - overloads of methods with covariant return types | | Do any of the languages allow you to modify a boxed value in place? For | instance, if I had a struct: | | public struct Foo | { | public int x; | } | | and put that into an ArrayList, in C# I certainly wouldn't be able to | modify the value in the list - I'd have to overwrite it with a new | boxed value after unboxing and modifying the other one, if you see what | I mean. | | My guess is that it's available in C++, but it doesn't hurt to know | these things... | way to do it either and the compiler won't generate code to modify "in-place" (AFIAK), at least not in a 'safe' context. In an unsafe context, I guess there is, but the question is; if it's more efficient than an unbox/modify/box trip? Willy. Willy Denoyette [MVP] <willy.denoye***@telenet.be> wrote:
> Don't know about other languages, but AFAIK the managed C++ language has no I seem to remember testing it in a sample program by modifying some IL > way to do it either and the compiler won't generate code to modify > "in-place" (AFIAK), at least not in a 'safe' context. > In an unsafe context, I guess there is, but the question is; if it's more > efficient than an unbox/modify/box trip? generated from C# - no need for unsafe code, it's just an IL unbox without a copy. I think it made a fairly significant difference, but only in a situation which is limited by this kind of operation happening a lot. Of course, generics solve this problem in a rather neater way anyway, if you're able to use 2.0 :) -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
Show quote
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message Jon,news:MPG.1e333cc1382d6d3898cce0@msnews.microsoft.com... | Willy Denoyette [MVP] <willy.denoye***@telenet.be> wrote: | > Don't know about other languages, but AFAIK the managed C++ language has no | > way to do it either and the compiler won't generate code to modify | > "in-place" (AFIAK), at least not in a 'safe' context. | > In an unsafe context, I guess there is, but the question is; if it's more | > efficient than an unbox/modify/box trip? | | I seem to remember testing it in a sample program by modifying some IL | generated from C# - no need for unsafe code, it's just an IL unbox | without a copy. I think it made a fairly significant difference, but | only in a situation which is limited by this kind of operation | happening a lot. Of course, generics solve this problem in a rather | neater way anyway, if you're able to use 2.0 :) | Sorry, I was only thinking about higher level languages, I'm sure it can be done in IL, however, I'm not sure it passes the verifier, remember (tweaked) IL is per definition 'unsafe' (well non-verifiable), Peverify is your friend here :-). Willy. >Do any of the languages allow you to modify a boxed value in place? This works for me:// Old syntax __value struct Foo { public: Foo(int x) { this->x = x; } virtual String * ToString() { return __box(x)->ToString(); } int x; }; int main() { Object *o = __box(Foo(42)); dynamic_cast<Foo*>(o)->x = 123; Console::WriteLine(o); return 0; } // New syntax, compiles with /clr:safe value struct Foo { public: Foo(int x) { this->x = x; } virtual String^ ToString() override { return x.ToString(); } int x; }; int main() { Object ^o = Foo(42); dynamic_cast<Foo^>(o)->x = 123; Console::WriteLine(o); return 0; } To add to the list of things you can't do in C#, VB or C++, I don't think any of them ever generates the tail. or cpblk IL instructions. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Hi all,
Mattias has given some interesting information. I will now find more about tail and cpblk. I thank you all for your help. I hope i get to hear more about this from more experts. I also would like to express my special thanks to john skeet. I have read many of his blogs and find it all very interesting. I feel honoured to see your reply on this thread john :). thanks pradeep Show quote "Mattias Sjögren" wrote: > >Do any of the languages allow you to modify a boxed value in place? > > This works for me: > > // Old syntax > __value struct Foo > { > public: > Foo(int x) { this->x = x; } > virtual String * ToString() { return __box(x)->ToString(); } > int x; > }; > > int main() > { > Object *o = __box(Foo(42)); > dynamic_cast<Foo*>(o)->x = 123; > Console::WriteLine(o); > return 0; > } > > // New syntax, compiles with /clr:safe > value struct Foo > { > public: > Foo(int x) { this->x = x; } > virtual String^ ToString() override { return x.ToString(); } > int x; > }; > > int main() > { > Object ^o = Foo(42); > dynamic_cast<Foo^>(o)->x = 123; > Console::WriteLine(o); > return 0; > } > > > To add to the list of things you can't do in C#, VB or C++, I don't > think any of them ever generates the tail. or cpblk IL instructions. > > > Mattias > > -- > Mattias Sjögren [C# MVP] mattias @ mvps.org > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > Please reply only to the newsgroup. > But, this doesn't modify the boxed value in place, it unboxes before
modifying. Take a look at the IL.... .... IL_0013: isinst Foo IL_0018: unbox Foo IL_001d: ldc.i4.s 123 IL_001f: stfld int32 Foo::x .... Willy. Show quote "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message news:e2dVtHTGGHA.1424@TK2MSFTNGP12.phx.gbl... | >Do any of the languages allow you to modify a boxed value in place? | | This works for me: | | // Old syntax | __value struct Foo | { | public: | Foo(int x) { this->x = x; } | virtual String * ToString() { return __box(x)->ToString(); } | int x; | }; | | int main() | { | Object *o = __box(Foo(42)); | dynamic_cast<Foo*>(o)->x = 123; | Console::WriteLine(o); | return 0; | } | | // New syntax, compiles with /clr:safe | value struct Foo | { | public: | Foo(int x) { this->x = x; } | virtual String^ ToString() override { return x.ToString(); } | int x; | }; | | int main() | { | Object ^o = Foo(42); | dynamic_cast<Foo^>(o)->x = 123; | Console::WriteLine(o); | return 0; | } | | | To add to the list of things you can't do in C#, VB or C++, I don't | think any of them ever generates the tail. or cpblk IL instructions. | | | Mattias | | -- | Mattias Sjögren [C# MVP] mattias @ mvps.org | http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com | Please reply only to the newsgroup. Willy,
>it unboxes before modifying. Right, but to quote the spec for the unbox instruction:"Unlike box, which is required to make a copy of a value type for use in the object, unbox is not required to copy the value type from the object. Typically it simply computes the address of the value type that is already present inside of the boxed object." If a copy that was modified, Console::WriteLine(o) would print the original value 42. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Show quote
"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message You are right of course (wasn't awake I guess when I replied), Unbox returns news:uAgMaodGGHA.1552@TK2MSFTNGP10.phx.gbl... | Willy, | | >it unboxes before modifying. | | Right, but to quote the spec for the unbox instruction: | | "Unlike box, which is required to make a copy of a value type for use | in the object, unbox is not required to copy the value type from the | object. Typically it simply computes the address of the value type | that is already present inside of the boxed object." | | | If a copy that was modified, Console::WriteLine(o) would print the | original value 42. | | | Mattias | | -- | Mattias Sjögren [C# MVP] mattias @ mvps.org | http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com | Please reply only to the newsgroup. a managed pointer the home of Foo::x) and the 'stfld' stores the value into the home of x. This is exactly what C# doesn't allow. Therefore, the following C# equivalent won't compile... object o = new Foo(42); ((Foo)o).x = 123; Willy. pradeep_TP wrote:
> Hi all, One feature is that all the high level languages I know about insist > > I was reading about MSIL and i came to know that there are some > features of CLR that can be only accessed by programming in IL. I > want to know what are these features which cannot be accessed by > languages like c# or vb.net that array indexes are 0-based, the CLI allows you to specify the range of the index (for a multi-dimensional array), and so it does not have to be 0-based. Richard -- Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm Security Tutorial: http://www.grimes.demon.co.uk/workshops/securityWS.htm |
|||||||||||||||||||||||