[Mono-list] VB.NET and C# differences in compiling

Marco Parenzan marco.parenzan@libero.it
Mon, 30 Sep 2002 14:35:18 +0200


Sorry....I have done a different compare.
The code correct is:

// VB
.method public instance int32  MyMethod(class MyClassVB o) cil managed
{
  // Code size       20 (0x14)
  .maxstack  2
  .locals init (int32 V_0,
           class MyClassVB V_1)
  IL_0000:  ldarg.1
  IL_0001:  stloc.1
  IL_0002:  ldarg.0
  IL_0003:  ldfld      int32 MyClassVB::mMyVar
  IL_0008:  ldloc.1
  IL_0009:  ldfld      int32 MyClassVB::mMyVar
  IL_000e:  add.ovf
  IL_000f:  stloc.0
  IL_0010:  br.s       IL_0012
  IL_0012:  ldloc.0
  IL_0013:  ret
} // end of method MyClassVB::MyMethod

// C#
.method public hidebysig instance int32  MyMethod(class MyClassCS o) cil
managed
{
  // Code size       20 (0x14)
  .maxstack  2
  .locals init (class MyClassCS V_0,
           int32 V_1)
  IL_0000:  ldarg.1
  IL_0001:  stloc.0
  IL_0002:  ldarg.0
  IL_0003:  ldfld      int32 MyClassCS::mMyVar
  IL_0008:  ldloc.0
  IL_0009:  ldfld      int32 MyClassCS::mMyVar
  IL_000e:  add
  IL_000f:  stloc.1
  IL_0010:  br.s       IL_0012
  IL_0012:  ldloc.1
  IL_0013:  ret
} // end of method MyClassCS::MyMethod

The order of istructions is different. Probably because C# tends to manage
params on the stack in a different manner.

About add.ovf, I have to see on C# specifications. I can think that C# is
something different from the CLI and can be implemented also on systems that
have not add.ovf equivalent (checking overflow cost a lot!). VB.NET runs
only on CLI so add.ovf is always present.....

Bye,
    Marco


----- Original Message -----
From: "Gaurav Vaish" <gaurav.vaish@amsoft.net>
To: "Marco Parenzan" <marco.parenzan@libero.it>; <mono-list@ximian.com>
Sent: Monday, September 30, 2002 1:17 PM
Subject: Re: [Mono-list] VB.NET and C# differences in compiling


> Hello Marco,
>
>     Thanks for these interesting examples.
>     I am still thinking as to why:
>     - local variable V_0 is missing in C# code?
>     - there is check for overflow (add.ovf) only in VB.Net (as opposed to
> add in C#)?
>
>     Ok, agree. We may give some arguments for having and not having V_0.
But
> "add" and "add.ovf" lead to two different things, shouldn't they - when
> overflow actually occurs?
>
>
>
> Happy hacking,
> Gaurav
> http://mastergaurav.virtualave.net/iitk