-16-

 

Appendix 1

 

Managed C++

 

There are many superficial differences between programming languages. Minor modifications have been carried out in the C++ programming language and, the modified language is called Managed Extensions for C++.

 

a.cpp

#using <mscorlib.dll>

using namespace System;

void main()

{

Console::WriteLine("hell");

}

 

We specify the dll that contains the code using a pre-processor directive #using. This pre-processor director works in the same manner in Managed C++ as it does in C#.

 

The C/C++ languages support global functions, and hence, Managed C++ also does so. Thus the function main is used with the letter "small m".

 

Static functions in C++ are separated from the class name by the symbol "::" . The same syntax is used here too. Thus, there is no variation from one .Net language to another, and since they all compile finally to IL, we can all use the same WriteLine function in any programming language that we like.

 

We compile the above program a.cpp into an executable as follows:

 

>cl /CLR a.cpp

 

As before we run ildasm and get the following output.

 

// VTableFixup Directory:

//   IMAGE_COR_VTABLEFIXUP[0]:

//       RVA:               00008038

//       Count:             0001

//       Type:              0005

//         [0000]            (06000001)

//   IMAGE_COR_VTABLEFIXUP[1]:

//       RVA:               00008730

//       Count:             0001

//       Type:              0001

//         [0000]            (06000002)

 

.subsystem 0x00000003

.corflags 0x00000002

.vtfixup [1] int32 fromunmanaged at D_00008038 // 06000001

.vtfixup [1] int32 at D_00008730 // 06000002

.assembly extern mscorlib

{

  .originator = (03 68 91 16 D3 A4 AE 33 )                

  .hash = (52 44 F8 C9 55 1F 54 3F 97 D7 AB AD E2 DF 1D E0

           F2 9D 4F BC )                                  

  .ver 1:0:2204:21

}

.assembly extern Microsoft.VisualC

{

  .originator = (03 68 91 16 D3 A4 AE 33 )               

  .hash = (A6 33 A5 3F A1 6E 0A F3 60 E1 22 E5 88 6E 72 5B

           48 5F 71 98 )                                 

  .ver 7:0:9030:0

}

.assembly a as "a"

{

  .hash algorithm 0x00008004

  .ver 0:0:0:0

}

.module a.exe

// MVID: {588ADAE2-1C64-11D5-A55B-88B2F731D07B}

.class value private explicit ansi sealed $MultiByte$size$5

       extends [mscorlib]System.ValueType

{

  .pack 1

  .size 5

} // end of class $MultiByte$size$5

 

//Global fields

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.field static privatescope value class $MultiByte$size$5 'unnamed-global-0$PST04000001' at D_00008030

//Global methods

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.method public static int32 modopt([mscorlib]System.Runtime.InteropServices.CallConvCdecl)

        main() il managed

{

  .vtentry 1 : 1

  // Code size       17 (0x11)

  .maxstack  1

  IL_0000:  ldsflda    value class $MultiByte$size$5 'unnamed-global-0$PST04000001'

  IL_0005:  newobj     instance void [mscorlib]System.String::.ctor(int8*)

  IL_000a:  call       void [mscorlib]System.Console::WriteLine(class System.String)

  IL_000f:  ldc.i4.0

  IL_0010:  ret

} // end of global method main

 

.method public static pinvokeimpl(/* No map */)

        unsigned int32 _mainCRTStartup() native unmanaged

{

  .entrypoint

  .custom instance void System.Security.SuppressUnmanagedCodeSecurityAttribute::.ctor() = ( 01 00 00 00 )

  .vtentry 2 : 1

  // Embedded native code

  //  Disassembly of native methods is not supported.

  //  Managed TargetRVA = 0x1

} // end of global method _mainCRTStartup

 

.data D_00008030 = bytearray (

                 68 65 6C 6C 00 00 00 00)                     

 

The code is quite large, but after reading it, you will realize that all the code generated in the .NET family of languages is similar. Thus, we believe that those who know IL have a great future in the world of computing.