Re: I think C# is forcing us to write more (redundant) code

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"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.


.



Relevant Pages

  • Re: -z preinitarray
    ... > able to reach the initialization code, ... > nothing done in the init section is required for proper initialization. ... > It has to depend on libc, ... BTW the entire allocator is ...
    (comp.unix.solaris)
  • Re: -z preinitarray
    ... then put the check for initialization in the slow ... Previously, I did most of my initialization in the init section; ... It has to depend on libc, ... caused the dependency loop; libC depends on libumem depends on libc ...
    (comp.unix.solaris)
  • Re: Non-constant initializers
    ... an init() which populates your globals' values, ... available at compile-time. ... Perhaps something like declaring an array ... If such a function used for initialization never returned (infinite ...
    (comp.lang.c)
  • Re: Default initialization and save
    ... My_default_init_type has default initialization, ... The explicit init of y overrides its ... The default init of xa get's applied on both allocations, ... subroutine nothing ...
    (comp.lang.fortran)
  • RE: I think C# is forcing us to write more (redundant) code
    ... After reading all the replies, I think my problem now turns into another ... Does the COR provide such a mechanism to ensure call ... Reflector does not give the 'init' flag. ... I guess the init flagtells the COR to initialize all local variables in ...
    (microsoft.public.dotnet.languages.csharp)