From: David Kastrup Date: Fri, 16 May 2008 14:14:54 GMT Subject: Re: [PATCH] mailsplit and mailinfo: gracefully handle NUL characters Message-ID: <86wsluuyht.fsf@lola.quinscape.zz> In-Reply-To: "Brian Foster" writes: > I'd tend to write this in terms of pointers, > something along the lines (untested): > > char *p, *endp; > > assert(1 <= size); > p = buf; > endp = p + (size-1); > while (p < endp) { > if ((c = getc(in)) == EOF || (*p++ = c) == '\n') > break; > } > *p = '\0'; > > return p - buf; Leave optimization to the compiler. Using pointer arithmetic more often than not screws up loop optimization and strength reduction. -- David Kastrup