Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Common Intermediate Language
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Pointer instructions - C++/CLI== A notable difference from Java's bytecode is that CIL comes with {{code|ldind}}, {{code|stind}}, {{code|ldloca}}, and many call instructions which are enough for data/function pointers manipulation needed to compile C/C++ code into CIL. <syntaxhighlight lang="cpp"> class A { public: virtual void __stdcall meth() {} }; void test_pointer_operations(int param) { int k = 0; int * ptr = &k; *ptr = 1; ptr = ¶m; *ptr = 2; A a; A * ptra = &a; ptra->meth(); } </syntaxhighlight> The corresponding code in CIL can be rendered as this: <syntaxhighlight lang="cpp"> .method assembly static void modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl) test_pointer_operations(int32 param) cil managed { .vtentry 1 : 1 // Code size 44 (0x2c) .maxstack 2 .locals ([0] int32* ptr, [1] valuetype A* V_1, [2] valuetype A* a, [3] int32 k) // k = 0; IL_0000: ldc.i4.0 IL_0001: stloc.3 // ptr = &k; IL_0002: ldloca.s k // load local's address instruction IL_0004: stloc.0 // *ptr = 1; IL_0005: ldloc.0 IL_0006: ldc.i4.1 IL_0007: stind.i4 // indirection instruction // ptr = ¶m IL_0008: ldarga.s param // load parameter's address instruction IL_000a: stloc.0 // *ptr = 2 IL_000b: ldloc.0 IL_000c: ldc.i4.2 IL_000d: stind.i4 // a = new A; IL_000e: ldloca.s a IL_0010: call valuetype A* modopt([mscorlib]System.Runtime.CompilerServices.CallConvThiscall) 'A.{ctor}'(valuetype A* modopt([mscorlib]System.Runtime.CompilerServices.IsConst) modopt([mscorlib]System.Runtime.CompilerServices.IsConst)) IL_0015: pop // ptra = &a; IL_0016: ldloca.s a IL_0018: stloc.1 // ptra->meth(); IL_0019: ldloc.1 IL_001a: dup IL_001b: ldind.i4 // reading the VMT for virtual call IL_001c: ldind.i4 IL_001d: calli unmanaged stdcall void modopt([mscorlib]System.Runtime.CompilerServices.CallConvStdcall)(native int) IL_0022: ret } // end of method 'Global Functions'::test_pointer_operations </syntaxhighlight>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Common Intermediate Language
(section)
Add topic