March 3, 2021
Hot Topics:

.NET Under the Hood: a Little ILDASM

  • By Kate Gregory
  • Send Email »
  • More Articles »

From Kate Gregory's Codeguru column, "Using Visual C++ .NET".

One of the really exciting things about working with .NET is the idea of a ".NET language"—a language that emits managed code and conforms to the Common Language Specification. And (at least in theory, anyway) if you write code in two or more of these languages, they will compile to the same intermediate language, or IL.

So, is C++ part of the in-crowd? Does a simple C++ application compile to the same IL as the equivalent Vb or C# application? Let's see.

Three Little Apps...

Here's a little C++ console application:

int _tmain(void)
    System::Int32 i;
    for (i=0; i<10; i++)
    return 0;

Here's the equivalent in C#:

static void Main(string[] args)
    System.Int32 i;
    for (i=0;i<10;i++)

And the same thing in VB:

Sub Main()
    Dim i As System.Int32
    For i = 0 To 9
End Sub

It's an interesting aside to see how names are assigned. I created a blank solution and added projects to it:

  • I named the C++ project SimpleC++, so I got a file called SimpleC++.cpp with a function called _tmain(). There was no namespace or class created.
  • I named the C# project SimpleCSharp (file names can't have the # symbol), so I got a file called Class1.cs. It defines the namespace SimpleCSharp, containing a class called Class1 with a function called Main().
  • I named the VB project SimpleVB, so I got a file called Module 1.vb. It defines the namespace SimpleVB, containing a module called Module1 with a Sub called Main().

All of these console applications do the same thing: print the numbers 0 to 9, one per line, on the console.

Page 1 of 2

This article was originally published on March 6, 2003

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date