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




"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.1d7d80f5d8ccc8ad98c626@xxxxxxxxxxxxxxxxxxxxxxx
> Willy Denoyette [MVP] <willy.denoyette@xxxxxxxxxx> wrote:
>> > No, that's not true for local variables. Local variables aren't
>> > assigned to anything by default, and can't be read until they've been
>> > definitely assigned.
>>
>> Actualy they are, the IL directive .locals init, emitted by C# , VB.NET
>> and
>> ME C++, is a hint for the JIT to initialize the locals (stack as well as
>> register allocated) to 0 (zero).
>
> That may be true of the implementation, but not of the specification. I
> should have made that clearer - it's actually important when it comes
> to calling methods with "out" parameters written in other languages,
> but within C# the value is effectively unspecified. This is perhaps
> unfortunate...
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too

Mind to tell us what specification are you talking about?
To me it's clear that C#, J#, C++ and VB.NET compilers emits a '.locals
init' directive and as a result the locals are initialized to zero. Sure,
the locals are not explicitely initialized (as per specification?), but all
(MS) compilers do emit the .local init directive in the method header,
question is based on what specification.
Not sure what 'out' parameters have to do with this, though, the callee
does/should not consider an out argument being 'initialized' by the caller,
the value it as doesn't matter anyway.


Willy.



.



Relevant Pages

  • Re: Is there any sense in using final keyword in catch block?
    ... I think the point of a final qualifier is to reassure the programmer that it won't change unexpectedly - it's an aid to reasoning about the code. ... local variables can only be accessed from inside the method they're local to; that's a much smaller body of code that the programmer has to keep in mind to know everything about the variable's use. ... If your method is big enough that making its locals final is helping you, then you need to split it up into multiple smaller methods. ...
    (comp.lang.java.programmer)
  • Re: Long.valueOf(long) CodeAttribute max_locals wrong?
    ... final int offset = 128; ... view" of local variables, or with the JVM view of local variables? ... Compiling code with debug information should provide proper initialization code for the final int offset, because debuggers may access the names and/or values of the local variables. ... public class Locals { ...
    (comp.lang.java.machine)
  • Re: proc A def/calls proc B: variable scoping rules.
    ... no. Scoping and duck typing are completely different concepts. ... # define both a and b as locals ... first it searches for it in the function's local variables, ...
    (comp.lang.python)
  • Re: Local variables controversial?
    ... >>> if you keep them on the stack the stack is minimally 4 deep, ... >> Graphics always comes up when locals are discussed. ... >> that don't ever require substandial stack thrashing OR local variables. ...
    (comp.lang.forth)
  • RfD: Enhanced local variable syntax
    ... The current LOCALS| ... ... to be initialised from the data stack. ... local buffers are much faster than using ALLOCATE ... The following syntax for local arguments and local variables is ...
    (comp.lang.forth)