Thread View: net.lang.c++
1 messages
1 total messages
Started by mayer
Mon, 28 Apr 1986 20:42
snextc function in class streambuf
Author: mayer
Date: Mon, 28 Apr 1986 20:42
Date: Mon, 28 Apr 1986 20:42
50 lines
1903 bytes
1903 bytes
From: mayer
The function "streambuf::snextc()" is undefined unless the stream buffer
has been filled at least once. In particular, the sequence:
filebuf input(0);
int c = input.snextc();
results in a segmentation fault. The problem could be fixed quite
easily by changing the implementation from:
inline int snextc()
{
return ((++gptr)==pptr) ? underflow() : *gptr & 0377;
}
to
inline int snextc()
{
return ((++gptr)>=pptr) ? underflow() : *gptr & 0377;
}
This wouldn't be any less efficient on most machines, and would allow
define "snextc" appropriately over the buffer's entire life.
By the way, replacing "*gptr & 0377" with "*(unsigned char *)gptr"
will save a little space and time on most machines. For example,
the SUN (V2) compiler produces:
movb a5@,d0
andl #255,d0
for the first implementation, and
moveq #0,d0
movb a5@,d0
for the second. This saves two 16 bit words of extention and 800ns on
each call. Perhaps the buffers should be "unsigned char" also. I
don't usually pick bits like this, but these routines are at the heart
of the IO system.
-- Jim
-- Jim Mayer University of Rochester
(arpa) mayer@Rochester.ARPA Department of Computer Science
(uucp) rochester!mayer Ray P. Hylan Building
(via allegra, decvax, or seismo) Rochester, New York 14627
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads