httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <...@algroup.co.uk>
Subject Re: [PATCH] Config File Line Continuation (take 3)
Date Tue, 03 Mar 1998 23:06:51 GMT
Rodent of Unusual Size wrote:
> 
> Ralf S. Engelschall wrote:
> >
> > In article <19980302151102.52337@deejai.mch.sni.de> you wrote:
> > > On Mon, Mar 02, 1998 at 10:10:43AM +0100, Ralf S. Engelschall wrote:
> > >> +            if (cp > cbuf && *(cp-1) == LF) {
> > >> +                cp--;
> > >> +                if (cp > cbuf && *(cp-1) == CR)
> > >> +                    cp--;
> > >> +                if (cp > cbuf && *(cp-2) == '\\'
> > >                                        ^Isn't this a cp[-1]?
> >
> > Ops, yes. The correct line should read:
> >                     if (cp > cbuf && *(cp-1) == '\\'
> > Thank's for the hint. Fixed.
> 
> That brings up a good point.  I think I'd rather see the char == byte
> assumptions omitted when code is added - things like this are going
> to make UNICODE and similar multi-byte charsets perfectly foul to
> handle.  (If and when.)
> 
> That is, I prefer "cp[-1]" to "*(cp - 1)".  Ben, is a negative index
> guaranteed safe for C arrays?

Others have responded, but I think they failed to spell out an important
point. cp[-1] is equivalent to *(cp-1) by definition (and an amusing
consequence is that it is therefore also equivalent to -1[cp]. Really)
as others have mentioned. What they failed to mention was that the
offset (-1 in this case) is scaled by sizeof *cp. So there is no "char
== byte" assumption, and no pain with UNICODE (well, no pain from this
kind of code). My objection is purely that it is ugly.

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|  Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |
A.L. Digital Ltd,     |Apache-SSL author    http://www.apache-ssl.org/
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache

Mime
View raw message