www.digitalmars.com         C & C++   DMDScript  

D - unused labels should cause an error

reply Robert <Robert_member pathlink.com> writes:
I suggest that unused labels should cause an error.
This prevents bugs due to typos of `default' label.

Robert (Japanese)
Dec 08 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Robert" <Robert_member pathlink.com> wrote in message
news:br1r2o$19i0$1 digitaldaemon.com...
 I suggest that unused labels should cause an error.
 This prevents bugs due to typos of `default' label.
I understand what you're saying. The problem with it, though, is that the label may be a target of a goto from inside a version statement elsewhere in the function. Wrapping the label in another version winds up looking kinda ugly. The default typo bug is alleviated somewhat by the language inserting a default:assert(0); if no other default is supplied.
Dec 08 2003
next sibling parent reply "Matthew Wilson" <matthew.hat stlsoft.dot.org> writes:
 I suggest that unused labels should cause an error.
 This prevents bugs due to typos of `default' label.
I understand what you're saying. The problem with it, though, is that the label may be a target of a goto from inside a version statement elsewhere
in
 the function. Wrapping the label in another version winds up looking kinda
 ugly.

 The default typo bug is alleviated somewhat by the language inserting a
 default:assert(0); if no other default is supplied.
Absolutely not. Your ability to flabbergast me on this issue has just expanded its borders. If the typo issue isn't compelling evidence in favour of a mandatory default, I can't conceive of what will be. :(
Dec 08 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Matthew Wilson" <matthew.hat stlsoft.dot.org> wrote in message
news:br3klk$uuk$1 digitaldaemon.com...
 I suggest that unused labels should cause an error.
 This prevents bugs due to typos of `default' label.
I understand what you're saying. The problem with it, though, is that
the
 label may be a target of a goto from inside a version statement
elsewhere
 in
 the function. Wrapping the label in another version winds up looking
kinda
 ugly.

 The default typo bug is alleviated somewhat by the language inserting a
 default:assert(0); if no other default is supplied.
Absolutely not. Your ability to flabbergast me on this issue has just expanded its borders. If the typo issue isn't compelling evidence in
favour
 of a mandatory default, I can't conceive of what will be.



 :(
I didn't try the compilers) are unreferenced labels an error. I'm not doesn't seem to be any consistent view in the C-like-language programming community how switch and labels ought to work.
Dec 09 2003
parent Robert <Robert_member pathlink.com> writes:
Hmm.  Though I think goto isn't a good example,
the problem may occur when labeled break is used.
I back it down.  ...since I've never done the typo, ...no,
I think now that this problem should be solved by other way
(e.g. improving switch statement syntax itself.)


In article <br417o$1iea$1 digitaldaemon.com>, Walter says...
"Matthew Wilson" <matthew.hat stlsoft.dot.org> wrote in message
news:br3klk$uuk$1 digitaldaemon.com...
 I suggest that unused labels should cause an error.
 This prevents bugs due to typos of `default' label.
I understand what you're saying. The problem with it, though, is that
the
 label may be a target of a goto from inside a version statement
elsewhere
 in
 the function. Wrapping the label in another version winds up looking
kinda
 ugly.

 The default typo bug is alleviated somewhat by the language inserting a
 default:assert(0); if no other default is supplied.
Absolutely not. Your ability to flabbergast me on this issue has just expanded its borders. If the typo issue isn't compelling evidence in
favour
 of a mandatory default, I can't conceive of what will be.



 :(
I didn't try the compilers) are unreferenced labels an error. I'm not doesn't seem to be any consistent view in the C-like-language programming community how switch and labels ought to work.
Robert (Japanese)
Dec 09 2003
prev sibling next sibling parent reply Richard Krehbiel <rich kastle.com> writes:
Walter wrote:
 "Robert" <Robert_member pathlink.com> wrote in message
 news:br1r2o$19i0$1 digitaldaemon.com...
 
I suggest that unused labels should cause an error.
This prevents bugs due to typos of `default' label.
I understand what you're saying. The problem with it, though, is that the label may be a target of a goto from inside a version statement elsewhere in the function. Wrapping the label in another version winds up looking kinda ugly.
I have myself coded the infamous "defualt:" goto-label, only to have my default case ignored. Then, I spent a day looking at the code and not seeing the misspelling. My own thought was to spell it "case default:" rather than just "default:" to make the difference more obvious.
Dec 09 2003
parent J C Calvarese <jcc7 cox.net> writes:
Richard Krehbiel wrote:

 Walter wrote:
 
 "Robert" <Robert_member pathlink.com> wrote in message
 news:br1r2o$19i0$1 digitaldaemon.com...

 I suggest that unused labels should cause an error.
 This prevents bugs due to typos of `default' label.
I understand what you're saying. The problem with it, though, is that the label may be a target of a goto from inside a version statement elsewhere in the function. Wrapping the label in another version winds up looking kinda ugly.
I have myself coded the infamous "defualt:" goto-label, only to have my default case ignored. Then, I spent a day looking at the code and not seeing the misspelling.
For me, using an editor that does syntax highlighting can help avoid this kind of error. YMMV. (Of course, if I haven't made any stupid programming mistakes recently, it's because I haven't worked on any programs recently.) Justin
 
 My own thought was to spell it "case default:" rather than just 
 "default:" to make the difference more obvious.
 
Dec 09 2003
prev sibling parent Juan C. <Juan_member pathlink.com> writes:
Another solution to a mispelled default looking like a label is my idea for a
new switch statement (as mentioned before) wherein the braces of a case are
required...

switch expr
{
case x
{
}

// no code allowed here

default
{
}
}

not only does this form of switch/case _not_ have a colon (and therefore not
look like a label), but no code (and therefore no labels) are allowed within the
switch but outside a case.

And of course I don't want fall-through, but that's another matter.  :)

In article <br3gdl$pan$1 digitaldaemon.com>, Walter says...
"Robert" <Robert_member pathlink.com> wrote in message
news:br1r2o$19i0$1 digitaldaemon.com...
 I suggest that unused labels should cause an error.
 This prevents bugs due to typos of `default' label.
I understand what you're saying. The problem with it, though, is that the label may be a target of a goto from inside a version statement elsewhere in the function. Wrapping the label in another version winds up looking kinda ugly. The default typo bug is alleviated somewhat by the language inserting a default:assert(0); if no other default is supplied.
Dec 09 2003