Thread overview
unused labels should cause an error
Dec 08, 2003
Robert
Dec 09, 2003
Walter
Dec 09, 2003
Matthew Wilson
Dec 09, 2003
Walter
Dec 09, 2003
Robert
Dec 09, 2003
Richard Krehbiel
Dec 09, 2003
J C Calvarese
Dec 09, 2003
Juan C.
December 08, 2003
I suggest that unused labels should cause an error.
This prevents bugs due to typos of `default' label.

Robert (Japanese)
December 09, 2003
"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.


December 09, 2003
> > 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.

Maybe I'll give up, and just program in C# ...

:(


December 09, 2003
"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.
>
> Maybe I'll give up, and just program in C# ...
>
> :(

FWIW, both C# and Java do the C-style implicit default:break;. The default is not mandatory. In neither C# nor Java (according to their specifications, I didn't try the compilers) are unreferenced labels an error. I'm not arguing that C# or Java did this right, I'm just pointing out that there doesn't seem to be any consistent view in the C-like-language programming community how switch and labels ought to work.


December 09, 2003
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.
>>
>> Maybe I'll give up, and just program in C# ...
>>
>> :(
>
>FWIW, both C# and Java do the C-style implicit default:break;. The default is not mandatory. In neither C# nor Java (according to their specifications, I didn't try the compilers) are unreferenced labels an error. I'm not arguing that C# or Java did this right, I'm just pointing out that there doesn't seem to be any consistent view in the C-like-language programming community how switch and labels ought to work.
>
>

Robert (Japanese)
December 09, 2003
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.

December 09, 2003
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.
>
>


December 09, 2003
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.
>