[Top][All Lists]

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

Re: CVS update: MODIFIED: src ...

From: Paul Edwards
Subject: Re: CVS update: MODIFIED: src ...
Date: Mon, 28 Jul 2003 13:36:19 GMT

"Derek Robert Price" <derek@ximbiot.com> wrote in message 
> Paul Edwards wrote:
> >"Derek Robert Price" <derek@ximbiot.com> wrote in message 
> >news:mailman.555.1059273520.8231.bug-cvs@gnu.org...
> >
> >
> >strip_trailing_newlines (char *str)
> >{
> >    size_t len, origlen;
> >    len = origlen = strlen (str);
> >
> >    while (len > 0 && str[len-1] == '\n' )
> >    {
> >        str[--len] = '\0';
> >    }
> >    return len != origlen;
> >}
> This is approximately what is in there already.  I just didn't check
> your last suggestion, assuming it would be only a semantic difference.

I don't think I would call it semantic.  It uses the proper (size_t)
variable on which to do string operations.

> I think the version checked in to subr.c actually uses one less
> operation each time through the loop, even if the variables aren't
> ideally named.

That depends on how smart the compiler is, but anyway, the
extra operation is required in order to cope with the extra
complexity of dealing with a size_t (unsigned).

The code currently checked in will not work on long strings,
where a long string is defined as something greater than
INT_MAX.  It is perfectly legitimate for a string to be that
long, and that's what size_t is for.  Probably more relevant
on a DOS/Win16 machine where INT_MAX is 32k, but you
can have a lot more memory than 32k.

BFN.  Paul.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]