[RFC] So, which is the correct type of _M_*_end - _M_*_cur?

Nathan Myers ncm-nospam@cantrip.org
Tue Apr 29 19:53:00 GMT 2003


On Tue, Apr 29, 2003 at 07:46:44PM +0200, Paolo Carlini wrote:
> reading and re-reading this code I noticed another minor
> inconsistency.
> 
>      size_t __buf_len = _M_in_end - _M_in_cur;
> 
> whereas, in the latter:
>
>      off_type __buf_len = _M_out_end - _M_out_cur;
> 
> Which one is right???

If you know that one pointer is more than the other (e.g. because
of a prior comparison, or because the invariants say you can assume 
it) then you should use size_t.  In this case there is no such 
invariant, so you should use ptrdiff_t, and using size_t is actually
wrong.  (The __copy_streambufs code I showed you has this mistake.)  

For streambufs, if the difference is negative -- xnext < xbeg, or 
xnext > xend, in standard terms -- it must be treated the same as 
zero.

Nathan Myers
ncm-nospam@cantrip.org



More information about the Libstdc++ mailing list