Re: I think C# is forcing us to write more (redundant) code
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Tue, 30 Aug 2005 10:21:30 +0200
"Neo The One" <NeoTheOne@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3BBCD509-6BB8-449B-B23B-2FF77A83B487@xxxxxxxxxxxxxxxx
> After reading all the replies, I think my problem now turns into another
> problem:
>
> Does the COR (Common Object Runtime) provide such a mechanism to ensure
> call
> lcoal variables have default values?
>
> If the COR guarantees that, then C# compiler is generating redundant code.
> Otherwise, VB compiler is generating WRONG code (as many of you have
> pointed
> out).
>
> Today, I used the ILDasm tool (part of .NET SDK) to examine the IL code
> generated both by C# and VB compilers. I found that the Lutz Roeder's
> Reflector does not give the 'init' flag. Here is the IL code ILDasm gives
> me:
>
> .locals init (string V_0)
>
> I guess the init flag(?) tells the COR to initialize all local variables
> in
> the parentheses.
>
> I also tried to read the IL reference (C:\Program
> Files\Microsoft.NET\SDK\v1.1\Tool Developers Guide\docs\Partition III
> CIL.doc), but that it does not have explanation about .locals instruction.
>
>
> Does anyone know where can I find a complete reference to IL instructions?
>
> Thanks.
>
Are you sure you did read all other replies, this is exactly what we are
talking about.
Point is, that C# requires explict initialization of locals before using
(which is a good thing!), but at the same time it emits the '.locals init'
directive that forces the JIT to generate initialization code too.
The latest CLI TR can be found here...
http://www.ecma-international.org/publications/standards/Ecma-335.htm
<quote>
If init is specified, the variables are initialized to their default values
according to their type:
reference types are initialized to null and value types are zeroed out.
[Note: Verifiable methods shall include the init keyword.....
</quote>
Willy.
Willy.
.
- Follow-Ups:
- Re: I think C# is forcing us to write more (redundant) code
- From: Neo The One
- Re: I think C# is forcing us to write more (redundant) code
- From: Neo The One
- Re: I think C# is forcing us to write more (redundant) code
- References:
- I think C# is forcing us to write more (redundant) code
- From: Neo The One
- RE: I think C# is forcing us to write more (redundant) code
- From: Neo The One
- I think C# is forcing us to write more (redundant) code
- Prev by Date: Re: button click
- Next by Date: Re: Assigning EventHandler of one control to another
- Previous by thread: RE: I think C# is forcing us to write more (redundant) code
- Next by thread: Re: I think C# is forcing us to write more (redundant) code
- Index(es):
Relevant Pages
|