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

Re: CLR and accessible features by Willy

Willy
Sat Jan 14 04:16:45 CST 2006


"pradeep_TP" <pradeepTP@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.



Re: CLR and accessible features by pradeepTP

pradeepTP
Sat Jan 14 06:17:02 CST 2006

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" <pradeepTP@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.
>
>
>

Re: CLR and accessible features by Naveen

Naveen
Sat Jan 14 07:43:31 CST 2006

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".


Re: CLR and accessible features by Willy

Willy
Sat Jan 14 08:48:05 CST 2006

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.

"pradeep_TP" <pradeepTP@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" <pradeepTP@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.
| >
| >
| >



Re: CLR and accessible features by Willy

Willy
Sat Jan 14 08:48:47 CST 2006


"Naveen" <naveensrinivasan.naveen@gmail.com> wrote in message
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".
|

However, it can be done in managed C++.

Willy.



Re: CLR and accessible features by Naveen

Naveen
Sat Jan 14 09:05:27 CST 2006

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.


Re: CLR and accessible features by Jon

Jon
Sat Jan 14 09:33:41 CST 2006

Willy Denoyette [MVP] <willy.denoyette@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...

--
Jon Skeet - <skeet@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

Re: CLR and accessible features by Willy

Willy
Sat Jan 14 09:42:57 CST 2006


"Naveen" <naveensrinivasan.naveen@gmail.com> wrote in message
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.
|

Ok, some nitpickng maybe, but the OP said "...by languages like C# and
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.



Re: CLR and accessible features by Willy

Willy
Sat Jan 14 10:32:12 CST 2006


"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1e332a3085fa441498ccdf@msnews.microsoft.com...
| Willy Denoyette [MVP] <willy.denoyette@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...
|

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?

Willy.





Re: CLR and accessible features by Jon

Jon
Sat Jan 14 10:52:51 CST 2006

Willy Denoyette [MVP] <willy.denoyette@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 :)

--
Jon Skeet - <skeet@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

Re: CLR and accessible features by Willy

Willy
Sat Jan 14 11:14:03 CST 2006


"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1e333cc1382d6d3898cce0@msnews.microsoft.com...
| Willy Denoyette [MVP] <willy.denoyette@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 :)
|

Jon,
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.





Re: CLR and accessible features by Mattias

Mattias
Sat Jan 14 11:40:22 CST 2006

>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.

Re: CLR and accessible features by pradeepTP

pradeepTP
Sat Jan 14 23:11:03 CST 2006

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

"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.
>

Re: CLR and accessible features by Willy

Willy
Sun Jan 15 07:21:48 CST 2006

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.


"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.



Re: CLR and accessible features by Mattias

Mattias
Sun Jan 15 07:44:09 CST 2006

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.

Re: CLR and accessible features by Willy

Willy
Sun Jan 15 10:21:15 CST 2006


"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
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.

You are right of course (wasn't awake I guess when I replied), Unbox returns
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.



Re: CLR and accessible features by Richard

Richard
Mon Jan 16 15:45:12 CST 2006

pradeep_TP wrote:
> 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

One feature is that all the high level languages I know about insist
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