[1+1=2]
OneAndOneIs2

Fri, May 02, 2008

[Link][Icon]K&R's reverse Polish notation calculator

Section 4.3, pages 76-78

I realise that this is a long shot, but: Can anyone tell me why the buffer used by getch() and ungetch() is an array of 100 chars?

Because no matter how I follow the logic, I can't see any way that you'll ever have more than one char going into the buffer: getop() only puts a maximum of one char into the buffer at the end of its run, and the first thing it does when it's called is to take a char from the buffer if there is one.

Am I missing something, or is this array here for future-proof flexibility or something?

2 comments • Categories: Omni, Programming

Comments:

Comment from: herd [Visitor] Email · http://erduman.de
I'd guess at historical reasons:
Back in 1969, when the keyboard controllers buffer was a whopping 8 bytes and dumb terminals were connected with a classy 300 baud, software buffering a whole line made a lot more sense than today...
PermalinkPermalink 02/05/08 @ 21:50
Comment from: oneandoneis2 [Member] · http://geekblog.oneandoneis2.org/
Buffering a whole line would make sense in that situation, but makes none in this context: It *never* gets more than a single character in the buffer, and yet the buffer is a 100-character array.

I can only assume it's to make the code more portable/versatile for future use elsewhere..
PermalinkPermalink 03/05/08 @ 21:07

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

Categories

August 2008
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Search

Misc

XML Feeds

What is this?
eXTReMe Tracker

Valid XHTML 1.0 Transitional

Valid CSS!

[Valid RSS feed]

powered by
b2evolution

blank