Jump to page: 1 212  
Page
Thread overview
Labeled statement and empty statement
Aug 14, 2003
Martin M. Pedersen
Aug 14, 2003
Mike Wynn
Aug 14, 2003
Charles Sanders
Aug 14, 2003
Martin M. Pedersen
Aug 15, 2003
Derek Parnell
Aug 15, 2003
Frank D. Wills
Aug 15, 2003
Vathix
Aug 15, 2003
Derek Parnell
Aug 15, 2003
Matthew Wilson
Aug 15, 2003
Mike Wynn
Aug 15, 2003
Matthew Wilson
Aug 15, 2003
DeadCow
Aug 16, 2003
Matthew Wilson
Aug 22, 2003
Ilya Minkov
Aug 15, 2003
Walter
Aug 15, 2003
Mike Wynn
Aug 15, 2003
Walter
Aug 16, 2003
Mike Wynn
Aug 16, 2003
Walter
Aug 15, 2003
John Reimer
Aug 15, 2003
Mike Wynn
Re: Labeled statement and empty statement -- OT
Aug 15, 2003
John Reimer
Aug 15, 2003
Mike Wynn
Aug 15, 2003
John Reimer
Aug 15, 2003
Matthew Wilson
Aug 15, 2003
John Reimer
Aug 16, 2003
Matthew Wilson
Aug 16, 2003
John Reimer
Aug 15, 2003
Matthew Wilson
Aug 15, 2003
John Reimer
Aug 16, 2003
Matthew Wilson
OT: Re: Labeled statement and empty statement
Re: Re: Labeled statement and empty statement
Aug 16, 2003
Matthew Wilson
Aug 16, 2003
John Reimer
OT: Re: Labeled statement and empty statement
Aug 16, 2003
John Reimer
Aug 15, 2003
Walter
Aug 16, 2003
John Reimer
Aug 16, 2003
Walter
Aug 16, 2003
Matthew Wilson
Aug 16, 2003
Matthew Wilson
Aug 15, 2003
Walter
Aug 16, 2003
John Reimer
Aug 16, 2003
Mike Wynn
Aug 16, 2003
John Reimer
Aug 16, 2003
Walter
Aug 16, 2003
John Reimer
Aug 16, 2003
Walter
Aug 16, 2003
Sean L. Palmer
Aug 16, 2003
Walter
Aug 16, 2003
Mike Wynn
Aug 16, 2003
Walter
Aug 16, 2003
Mike Wynn
Aug 16, 2003
Sean L. Palmer
Aug 19, 2003
Bill Cox
Aug 15, 2003
Walter
Aug 18, 2003
Derek Parnell
Aug 15, 2003
Matthew Wilson
Aug 15, 2003
Frank D. Wills
Aug 15, 2003
Frank D. Wills
Aug 15, 2003
Sean L. Palmer
Aug 15, 2003
Frank D. Wills
Aug 16, 2003
Matthew Wilson
Aug 16, 2003
Sean L. Palmer
Aug 15, 2003
Matthew Wilson
Aug 15, 2003
Frank D. Wills
Aug 15, 2003
Ilya Minkov
Aug 15, 2003
Frank D. Wills
Aug 15, 2003
Mike Wynn
Aug 15, 2003
Frank D. Wills
Aug 16, 2003
Walter
Aug 15, 2003
Benji Smith
Aug 15, 2003
Patrick Down
Aug 15, 2003
Charles Sanders
Aug 16, 2003
Walter
Aug 18, 2003
Charles Sanders
OT - Re: Labeled statement and empty statement
Aug 15, 2003
Frank D. Wills
Aug 16, 2003
Sean L. Palmer
Aug 16, 2003
Sean L. Palmer
Aug 16, 2003
Walter
Aug 16, 2003
Mike Wynn
Aug 16, 2003
Walter
Aug 16, 2003
Matthew Wilson
Aug 16, 2003
Matthew Wilson
Aug 15, 2003
Benji Smith
Aug 15, 2003
Ilya Minkov
Aug 15, 2003
Sean L. Palmer
Aug 15, 2003
Ilya Minkov
Aug 16, 2003
Sean L. Palmer
Aug 15, 2003
Philippe Mori
Aug 15, 2003
Walter
Aug 15, 2003
Mike Wynn
Aug 16, 2003
Walter
Aug 16, 2003
Mike Wynn
Aug 16, 2003
Walter
Aug 17, 2003
Philippe Mori
Aug 17, 2003
Walter
Aug 17, 2003
Mike Wynn
Aug 17, 2003
Walter
Aug 17, 2003
Mike Wynn
Aug 16, 2003
Frank D. Wills
Aug 16, 2003
Sean L. Palmer
Aug 18, 2003
Derek Parnell
Aug 16, 2003
Walter
Aug 16, 2003
Mike Wynn
Aug 16, 2003
Walter
Aug 16, 2003
Mike Wynn
Aug 16, 2003
Walter
Aug 16, 2003
Ilya Minkov
Aug 16, 2003
Matthew Wilson
August 14, 2003
Hi,

In C it is common to see functions like this:

    void foo(void)
    {
        // do something useful
        if (error) {
            goto done;
        }
        // do something useful
    done:
        // clean up
    }

In are more concrete example, it could end like this:

        ...
    done:
        fclose(fp);
        free(ptr);
    }

The code is maintained, and for some reason there is no need for fclose()
and free() anymore. But there are numerous goto's to the label, and we want
to keep the single exit point. So it is changed to:

        ...
    done:
    }

But this will not compile, because there is no statement after "done:". In C we need to use the empty statement like this:

        ...
    done:
        ;
    }

Silly, isn't it? In D, if the documentation is correct, it is even worse, because there is no empty statement. So we need to write something like:

        ...
    done:
        { }
    }

or
        ...
    done:
        0;
    }

But it appears that DMD actually implements the empty statement, so the
documentation and DMD is out of sync here.
I just wish there was no need for the empty statement. It t would be more
elegant if labels didn't need to prefix a statement.


Regards,
Martin


August 14, 2003
"Martin M. Pedersen" <martin@moeller-pedersen.dk> wrote in message news:bhgbl8$ac3$1@digitaldaemon.com...
> Hi,
>
> In C it is common to see functions like this:
>
>     void foo(void)
>     {
>         // do something useful
>         if (error) {
>             goto done;
>         }
>         // do something useful
>     done:
>         // clean up
>     }
>
> In are more concrete example, it could end like this:
>
>         ...
>     done:
>         fclose(fp);
>         free(ptr);
>     }
>
> The code is maintained, and for some reason there is no need for fclose()
> and free() anymore. But there are numerous goto's to the label, and we
want
> to keep the single exit point. So it is changed to:
>
>         ...
>     done:
>     }
>
> But this will not compile, because there is no statement after "done:". In
C
> we need to use the empty statement like this:
>
>         ...
>     done:
>         ;
>     }
>
> Silly, isn't it? In D, if the documentation is correct, it is even worse, because there is no empty statement. So we need to write something like:
>
>         ...
>     done:
>         { }
>     }
>
> or
>         ...
>     done:
>         0;
>     }
>
> But it appears that DMD actually implements the empty statement, so the
> documentation and DMD is out of sync here.
> I just wish there was no need for the empty statement. It t would be more
> elegant if labels didn't need to prefix a statement.
>
you should use a labled block and change your goto's to a break
 done : {
    ....
    if ( error ) { break done; }
    ...
    return;
}
// clean up.

or if you want to be more OO change it to
try {
    if ( error ) { throw new Exception(); }
    // or a staticly held exception if you worred about performance
} catch( Exception e ) {
} // [finally ....]




August 14, 2003
> It t would be more
> elegant if labels didn't need to prefix a statement.

It would be more elegenat if you didnt use goto's :P.

Charles

"Martin M. Pedersen" <martin@moeller-pedersen.dk> wrote in message news:bhgbl8$ac3$1@digitaldaemon.com...
> Hi,
>
> In C it is common to see functions like this:
>
>     void foo(void)
>     {
>         // do something useful
>         if (error) {
>             goto done;
>         }
>         // do something useful
>     done:
>         // clean up
>     }
>
> In are more concrete example, it could end like this:
>
>         ...
>     done:
>         fclose(fp);
>         free(ptr);
>     }
>
> The code is maintained, and for some reason there is no need for fclose()
> and free() anymore. But there are numerous goto's to the label, and we
want
> to keep the single exit point. So it is changed to:
>
>         ...
>     done:
>     }
>
> But this will not compile, because there is no statement after "done:". In
C
> we need to use the empty statement like this:
>
>         ...
>     done:
>         ;
>     }
>
> Silly, isn't it? In D, if the documentation is correct, it is even worse, because there is no empty statement. So we need to write something like:
>
>         ...
>     done:
>         { }
>     }
>
> or
>         ...
>     done:
>         0;
>     }
>
> But it appears that DMD actually implements the empty statement, so the
> documentation and DMD is out of sync here.
> I just wish there was no need for the empty statement. It t would be more
> elegant if labels didn't need to prefix a statement.
>
>
> Regards,
> Martin
>
>


August 14, 2003
"Charles Sanders" <sanders-consulting@comcast.net> wrote in message news:bhgdqv$cfh$1@digitaldaemon.com...
> It would be more elegenat if you didnt use goto's :P.

I know, but still, "goto" is part of the language.

Regards,
Martin


August 15, 2003
On Thu, 14 Aug 2003 19:34:43 +0200 (08/15/03 03:34:43)
, Martin M. Pedersen <martin@moeller-pedersen.dk> wrote:

> "Charles Sanders" <sanders-consulting@comcast.net> wrote in message
> news:bhgdqv$cfh$1@digitaldaemon.com...
>> It would be more elegenat if you didnt use goto's :P.
>
> I know, but still, "goto" is part of the language.
>

Yes, but that neither compels you to use it, or to make it a part of your 'language'.



-- 
Derek
August 15, 2003
I suppose the goto statement isn't a big issue, but it's the
first thing I would want to remove from all languages except
it's equivalent, the jump statement on assembler, where it's
needed. Otherwise nothing worse or uglier than a goto statement.


Derek Parnell wrote:
> On Thu, 14 Aug 2003 19:34:43 +0200 (08/15/03 03:34:43)
> , Martin M. Pedersen <martin@moeller-pedersen.dk> wrote:
> 
>> "Charles Sanders" <sanders-consulting@comcast.net> wrote in message
>> news:bhgdqv$cfh$1@digitaldaemon.com...
>>
>>> It would be more elegenat if you didnt use goto's :P.
>>
>>
>> I know, but still, "goto" is part of the language.
>>
> 
> Yes, but that neither compels you to use it, or to make it a part of your 'language'.
> 
> 
> 

August 15, 2003
I like goto.

"Frank D. Wills" <fdwills@sandarh.com> wrote in message news:bhh9ic$1853$1@digitaldaemon.com...
> I suppose the goto statement isn't a big issue, but it's the first thing I would want to remove from all languages except it's equivalent, the jump statement on assembler, where it's needed. Otherwise nothing worse or uglier than a goto statement.
>
>
> Derek Parnell wrote:
> > On Thu, 14 Aug 2003 19:34:43 +0200 (08/15/03 03:34:43)
> > , Martin M. Pedersen <martin@moeller-pedersen.dk> wrote:
> >
> >> "Charles Sanders" <sanders-consulting@comcast.net> wrote in message news:bhgdqv$cfh$1@digitaldaemon.com...
> >>
> >>> It would be more elegenat if you didnt use goto's :P.
> >>
> >>
> >> I know, but still, "goto" is part of the language.
> >>
> >
> > Yes, but that neither compels you to use it, or to make it a part of your 'language'.
> >
> >
> >
>


August 15, 2003
On Fri, 15 Aug 2003 00:49:10 -0400 (08/15/03 14:49:10)
, Vathix <vathix@dprogramming.com> wrote:

> I like goto.

And I like McDonald's BigMacs, but it doesn't mean they're good for me.

-- 
Derek
August 15, 2003
> > I know, but still, "goto" is part of the language.
> >
>
> Yes, but that neither compels you to use it, or to make it a part of your 'language'.

If it's in, then its use should make sense.

(Not that I'm coming down on any side of the goto debate here.)


August 15, 2003
"Frank D. Wills" <fdwills@sandarh.com> wrote in message news:bhh9ic$1853$1@digitaldaemon.com...
> I suppose the goto statement isn't a big issue, but it's the first thing I would want to remove from all languages except it's equivalent, the jump statement on assembler, where it's needed. Otherwise nothing worse or uglier than a goto statement.

Don't mean to offend, but this sounds terribly naive. Just because something is rightly deprecated in most circumstances does not mean it does not have a use. I rarely use it, probably a couple of times a year, but when I do it is the appropriate tool for the job in hand, so I use it.



« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11