[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

RE: C programming question...[OT]



> --- Steve Borho <steve borho org> wrote:
> > Speaking to just pure style, though, that while loop
> > reminds me of the
> > most efficient C snippet I've ever seen.  It's the
> > standard implementation
> > of strcpy.
> > 
> >     for (;*s;)
> >       *d++ = *s++;
> 
> 
> One question about this code snippet: Won't it fail to copy
> the terminating '\0' into the target string?

Well, first, it's not really what I'd consider the classic
strcpy:

	while (*d++ = *s++);

That one will copy the null on the last iteration (the one
that fails the test).

Mike McNally | Turtle, turtle, on the ground,
m5 works com | Pink and shiny, turn around.
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]