www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Labels as values

reply "Martin M. Pedersen" <martin moeller-pedersen.dk> writes:
GCC has a feature that I have sometimes whished for: "computed gotos". They 
are described here:
http://www.tac.dk/cgi-bin/info2www?(gcc.info)Labels%20as%20Values

Although, I don't like the syntax, I do like the concept. In normal code, 
they are not terribly useful, but in generated code such as the output of 
"lex", it is a handy feature. I see it primarily as a tool for creating 
intraprocedural jump tables.

Would it be a valuable addition to D? It seems to be an easy thing to do.

Regards,
Martin
Mar 01 2005
next sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Martin M. Pedersen" <martin moeller-pedersen.dk> wrote in message
news:d02o6p$udo$1 digitaldaemon.com...
 GCC has a feature that I have sometimes whished for: "computed gotos".
They
 are described here:
 http://www.tac.dk/cgi-bin/info2www?(gcc.info)Labels%20as%20Values

 Although, I don't like the syntax, I do like the concept. In normal code,
 they are not terribly useful, but in generated code such as the output of
 "lex", it is a handy feature. I see it primarily as a tool for creating
 intraprocedural jump tables.

 Would it be a valuable addition to D? It seems to be an easy thing to do.
I once looked into adding it to the C compiler. But since the switch statement already generates indexed jump tables, it was hard to see what advantage they'd have.
Mar 01 2005
parent "Martin M. Pedersen" <martin moeller-pedersen.dk> writes:
"Walter" <newshound digitalmars.com> skrev i en meddelelse 
news:d03kkj$1tus$1 digitaldaemon.com...
 I once looked into adding it to the C compiler. But since the switch
 statement already generates indexed jump tables, it was hard to see what
 advantage they'd have.
Ok, I see your point. Regards, Martin
Mar 02 2005
prev sibling parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Martin M. Pedersen wrote:
 GCC has a feature that I have sometimes whished for: "computed gotos". They 
 are described here:
 http://www.tac.dk/cgi-bin/info2www?(gcc.info)Labels%20as%20Values
 
 Although, I don't like the syntax, I do like the concept. In normal code, 
 they are not terribly useful, but in generated code such as the output of 
 "lex", it is a handy feature. I see it primarily as a tool for creating 
 intraprocedural jump tables.
 
 Would it be a valuable addition to D? It seems to be an easy thing to do.
I pondered this a few months ago (not knowing that GCC already had it). What I found, at least for my purposes, was that delegates worked just about as well. You can construct a jump table as an array of delegates.
Mar 02 2005