Class forward declaration in Intermediate Language RRS feed

  • Question

  • User-1952780613 posted
    Hi, I have a somewhat unusual question I beleive. I'm not sure that it belong to this forum but why not try, since Intermediate Language is a .NET language. I am trying to learn Intermediate Language for a special purpose :) . I am mainly focusing on very small programs with printing out strings to the console, a few variables, both local and class variables, inheritance etc. I am writing Intermediate Language like this: class c{ method m{ ... } } When I have create programs in C#, use the csc compiler to create .exe files and then use ildasm to see the IL code generated by csc. The code is structured like this: class c { } method m { ... } When I take the code from ildasm generated by csc, put it in a .il file and compile it with ilasm it does not work. ilasm complains about methods with the keywords static and instance. It also complains about duplicate methods, all the constructors in the classes, since all methods become global. I am able to compile all small programs if I structure them " as usual" (as in the first code example) with methods within the classes. Questions: 1. Does anyone know why there is differences in the IL code that csc generates and the IL code ilasm compiles, and if it is possible to read about that somewhere? 2. Have tried to find some good IL web sites with more examples than Hello World, but not succeeded so well. Does anyone know good IL sites? 3. Is there even a forum for IL somewhere that someone could recommend? /Moorstream
    Thursday, April 1, 2004 1:16 PM

All replies

  • User479087710 posted
    Can you please paste exactly what you are writing and exactly what ildasm generates? You are wondering why methods are being declared outside the context of a class? It could be that csc is taking the .entrypoint method that is declared as static void Main() and placing it outside the context of the class. This would seem fine to me, since the requirement that methods be declared inside a class is an artifact of c#, not IL. I learned IL from a book called Advanced .NET Programming by wrox press. The author does an amazing (really, amazing) job at explaining IL and it's relationship to the higher level languages, as well as it's relationship to the CLR. Get this book if you want to learn IL. Just get this book anyways.
    Sunday, July 4, 2004 1:57 AM
  • User479087710 posted
    Mmm. Actually it seems unlikely that csc is changing the visibility declaration of any methods or moving them outside a class. Please post your code (both handwritten and disassembled).
    Sunday, July 4, 2004 1:59 AM