Re: how to replace a substring in a string using C?
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Thu, 10 Nov 2005 13:12:40 GMT
Netocrat wrote:
> > size_t count;
> > count = q - p;
>
> As discussed elsethread,
> under C99 this invokes undefined behaviour when q - p > PTRDIFF_MAX.
> I vaguely recall discussions on the semantics under
> C89, but can't recall the conclusion. Also under C99 count would be
> better declared ptrdiff_t but it appears that you're writing to C89.
Whether or not to declare count ptrdiff_t,
is not really an 89 vs 99 issue.
The type of the expression, (q - p), is ptrdiff_t.
If there's going to be undefined behavior,
it's going to be from that expression.
While there is no PTRDIFF_MAX macro in C89,
there is still a maximum limit to the ptrdiff_t type,
there's just no portable way to tell what is.
I suppose you can assume that it's at least 127.
--
pete
.
- Follow-Ups:
- Re: how to replace a substring in a string using C?
- From: Netocrat
- Re: how to replace a substring in a string using C?
- References:
- Re: how to replace a substring in a string using C?
- From: Mark F. Haigh
- Re: how to replace a substring in a string using C?
- From: Netocrat
- Re: how to replace a substring in a string using C?
- Prev by Date: Re: [OT] Re: How to read arrow key input in the ANSI way?
- Next by Date: Re: Best way of clearing a compiler warning?
- Previous by thread: Re: how to replace a substring in a string using C?
- Next by thread: Re: how to replace a substring in a string using C?
- Index(es):
Relevant Pages
|