Re: Is this str_rev() ok?
Skarmander wrote:[color=blue]
>
> Skarmander wrote:[color=green]
> > pete wrote:[color=darkred]
> >> Skarmander wrote:[/color][/color][/color]
[color=blue][color=green][color=darkred]
> >>> In the unlikely case I have to implement strcpy()
> >>> in standard C, I'd probably use
> >>>
> >>> while ((*dest++ = *source++) != '\0');
> >>
> >> An equality expression with three side effects,
> >> is a little too busy for my taste.
> >>
> >> I'm more partial to:
> >> do {
> >> *dest = *source++;
> >> } while (*dest++ != '\0');
> >>[/color]
> > I thought about this, but in the end,
> > the urge to keep the symmetry of
> > the ++ operators was just too strong to ignore.
> >
> > If I really wanted to split up all the side effects, of which I'm no
> > great fan either, I'd go all the way:
> >
> > for (;;)
> > *dest = *source*;[/color]
>
> Typo, obviously. Some newsreaders will helpfully *highlight* it. :-)[/color]
I avoid break statements when it's not too hard to do.
I also prefer
for (rc = getc(fp); rc != EOF; rc = getc(fp))
to
while ((rc = getc(fp)) != EOF)
I guess it's not necessarily the "three side effects"
in an equality expression that I don't like.
--
pete
Skarmander wrote:[color=blue]
>
> Skarmander wrote:[color=green]
> > pete wrote:[color=darkred]
> >> Skarmander wrote:[/color][/color][/color]
[color=blue][color=green][color=darkred]
> >>> In the unlikely case I have to implement strcpy()
> >>> in standard C, I'd probably use
> >>>
> >>> while ((*dest++ = *source++) != '\0');
> >>
> >> An equality expression with three side effects,
> >> is a little too busy for my taste.
> >>
> >> I'm more partial to:
> >> do {
> >> *dest = *source++;
> >> } while (*dest++ != '\0');
> >>[/color]
> > I thought about this, but in the end,
> > the urge to keep the symmetry of
> > the ++ operators was just too strong to ignore.
> >
> > If I really wanted to split up all the side effects, of which I'm no
> > great fan either, I'd go all the way:
> >
> > for (;;)
> > *dest = *source*;[/color]
>
> Typo, obviously. Some newsreaders will helpfully *highlight* it. :-)[/color]
I avoid break statements when it's not too hard to do.
I also prefer
for (rc = getc(fp); rc != EOF; rc = getc(fp))
to
while ((rc = getc(fp)) != EOF)
I guess it's not necessarily the "three side effects"
in an equality expression that I don't like.
--
pete
Comment