tags:

views:

221

answers:

5
+1  Q: 

Code Curiosity

I was looking at the YUI Compressor and came across this piece of code in the ECMA.NET project (Continuation file if you are interested).

protected internal override int FindPrototypeId (string s)
    {
        int id;
        #region Generated PrototypeId Switch
    L0: {
            id = 0;
            string X = null;
            if (s.Length == 11) { X = "constructor"; id = Id_constructor; }
            if (X != null && X != s && !X.Equals (s))
                id = 0;
        }
    EL0:
        #endregion
        return id;
    }

I have no idea what L0: and EL0: are doing here and have never seen this before. The term seems too rudimentary for google as well.

Anyone know anything about this?

+9  A: 

They look like lables for use as goto targets. See http://msdn.microsoft.com/en-us/library/13940fs2.aspx for more information.

Scott Dorman
I was afraid of that.
Ty
C# has goto's? ...
C. Ross
@Ty, @C. Ross: Yes, C# has goto's. In fact, loops are really nothing more than syntax sugar around a goto.
Scott Dorman
+5  A: 

They look like labels to me. The label is not used in this example (because it is generated code?), but can be used to jump another place. You could use goto L0; to jump the the first label. As an example, the following code writes just "Hello, World" because it skips the middle Write():

Console.Write("Hello, ");
goto Last;
Console.Write("Cruel ");
Last:
Console.WriteLine("World");
Jordan Miner
+2  A: 

Those are labels, as in GOTO.

John Saunders
A: 

L0 and EL0 look like labels for the goto statement

trendl
+1  A: 

They're obviously labels, but I don't think that they're used as goto targets. I imagine that they're designed to be recognized by a code generation tool of some kind. The code generation tool "owns" the code between L0 and EL0, which probably just means "end L0."