what'd the difference between STDIN and Keyboard buffer ?

H

herrcho

What's the difference between STDIN and Keyboard buffer ?

when i get char through scanf, i type in some characters and press
enter,
then, where do the characters go ? to STDIN or Keyboard buffer ? are
they same ?

thanks ^^
 
M

Mike Wahler

herrcho said:
What's the difference between STDIN and Keyboard buffer ?

As to the standard C language, nothing. Neither has
anything to do with it.

However, 'stdin' (note the lower case) is the identifier
that the C standard library uses to designate the 'standard
input stream' of a program.

C has no support for any particular hardware devices,
be they keyboards, meeces, video displays, or whatever.
All i/o is abstracted as 'streams of characters'.
when i get char through scanf, i type in some characters and press
enter,
then, where do the characters go ?

They're stored in the object whose address you must
have supplied as an argument to 'scanf()'? What
happens between the time the user presses the keys
and the point where your data is present in your
varaible depends upon your platform, and is not
addressed by the C language, which is platform
independent.

to STDIN or Keyboard buffer ? are
they same ?

See above.

BTW what is the motivation for your questions?

-Mike
 
O

osmium

Mike said:
See above.

BTW what is the motivation for your questions?

Sounds to me like another one of those guys that just like to *know* things.
Perhaps he realizes how much this irritates you.
 
M

Martijn

Mike said:
C has no support for any particular hardware devices,
be they keyboards, meeces, video displays, or whatever.
All i/o is abstracted as 'streams of characters'.

What the h*** are "meeces"? Is that the plural for mice ;) (which in turn
is plural for mouse)?
 
P

pete

Mike said:
As to the standard C language, nothing. Neither has
anything to do with it.

However, 'stdin' (note the lower case) is the identifier
that the C standard library uses to designate the 'standard
input stream' of a program.

It's a bit of sloppiness on the part of both K&R2 and the standard,
to use stdin that way.
stdin is described as being an expression of type pointer to FILE.
FILE is an object type capable of recording all the information
needed to control a stream.
The object that stdin points to,
is associated with the standard input stream.
 
D

Dan Pop

In said:
What's the difference between STDIN and Keyboard buffer ?

when i get char through scanf, i type in some characters and press
enter,
then, where do the characters go ? to STDIN or Keyboard buffer ? are
they same ?

Your question makes sense only if stdin is connected to an interactive
terminal. Although this is quite common, keep in mind that it is not
necessarily the case, on many implementations stdin can be connected
to a file or some other kind of device.

To understand the difference between stdin and keyboard buffer, you
must realise that stdin is a C library concept and it is implemented at
that level, while the keyboard buffer is an operating system concept (and
implemented at that level).

So, the characters you type go into the keyboard buffer (you may type them
even at a time when the program doesn't wait for stdin input, so something
must take care of them). When your program needs input from stdin, an
input function from the standard library implementation asks the OS to
deliver the contents of the keyboard buffer as soon as it may be made
available to the program. At that point, the characters get moved from
the keyboard buffer into stdin's buffer.

Of course, this is not the only scenario possible in practice and things
are also affected by the buffering mode of stdin (line-buffered or
non-buffered) and by the buffering mode of the terminal driver of your OS
(characters may be delivered to the application only when a newline is
already in the keyboard buffer or at any time). But you get a general
idea about the difference between the two.

Dan
 
M

Mike Wahler

Martijn said:
What the h*** are "meeces"?

Me sez I can use poetic license. :)

" Is that the plural for mice ;) (which in turn
is plural for mouse)?

Something like that. Just having a bit of fun. :)

I suppose being from NL you don't know the reference::
The old U.S. cartoon show from the sixties, "Tom and
Jerry", about two mice and their nemesis, the cat
that frequently says after being outsmarted:
"I hate those meeces to pieces!" :)

-Mike
 
D

Dan Pop

In said:
stdin, OTOH, is *strictly* a software concept. I am not a historian but my
first guess is that it goes back to the standard '5', or whatever, used in
Fortran I/O. Which used to be spelled FORTRAN.

It's actually '*' in FORTRAN and it stands for both "standard input"
and "standard output", but I'm not sure at what point it became a standard
FORTRAN feature (it is specified by F77, but I used F-IV compilers that
didn't support it).

Dan
 
O

osmium

pete said:
It's a bit of sloppiness on the part of both K&R2 and the standard,
to use stdin that way.
stdin is described as being an expression of type pointer to FILE.
FILE is an object type capable of recording all the information
needed to control a stream.
The object that stdin points to,
is associated with the standard input stream.

I don't know what that means so I won't argue. (I don't know what "use
stdin that way" means. What is 'that'?) My answer would be that the
keyboard buffer is a useful *hardware* thing, even though the phrase itself
and the messy details are handled by software. God did not ordain that
there be a keyboard buffer. A good way to partition the workload and
minimize the number of hardware interrupts is to provide the rudiments
needed to allow keyboard buffers. If you look at a DOS era machine, you
already have the beginnings of multi-tasking: input and editing are distinct
from computing.

stdin, OTOH, is *strictly* a software concept. I am not a historian but my
first guess is that it goes back to the standard '5', or whatever, used in
Fortran I/O. Which used to be spelled FORTRAN.
 
D

Default User

Mike said:
I suppose being from NL you don't know the reference::
The old U.S. cartoon show from the sixties, "Tom and
Jerry", about two mice and their nemesis, the cat
that frequently says after being outsmarted:
"I hate those meeces to pieces!" :)

<cartoon pedantry>

Actually, that was from the adventures of Trixie and Dixie (the meeces)
and Jinx the cat. In classic Tom & Jerry, neither ever spoke.

</cartoon pedantry>




Brian Rodenborn
 
M

Mike Wahler

Default User said:
<cartoon pedantry>

Actually, that was from the adventures of Trixie and Dixie (the meeces)
and Jinx the cat. In classic Tom & Jerry, neither ever spoke.

</cartoon pedantry>

Oh, yeah, you're right.

I guess this stuff dates me pretty well, and exposes my
faulty memory. Mental segfault. :)

-Mike
 
R

Richard Heathfield

Default said:
Actually, that was from the adventures of Trixie and Dixie (the meeces)
and Jinx the cat.

To be boring for a moment re "meeces": the mouse's inventor, Doug Engelbart
(who is, perhaps, the only one we might expect to have a definitive
opinion), says he "doesn't know" the plural of "mouse" (in the computer
peripheral sense), which leaves us free to use whatever name we like best.

Microsoft recommend "mouse devices", but of course everybody ignores them.
IME the mindshare seems to be split between "mice", "mouses", and "meeces"
(in descending order of popularity).
In classic Tom & Jerry, neither ever spoke.

This is an easy statement to justify, since any cartoon in which either Tom
or Jerry speaks is clearly /not/ a classic. :)
 
D

Default User

Richard said:
Microsoft recommend "mouse devices", but of course everybody ignores them.
IME the mindshare seems to be split between "mice", "mouses", and "meeces"
(in descending order of popularity).

I prefer "mouses" myself, but "mice" seems popular around the office.
This is an easy statement to justify, since any cartoon in which either Tom
or Jerry speaks is clearly /not/ a classic. :)


By classic I meant created by MGM for theater(re) showings. Only some
later made-for-TV T&Js had speaking parts (and much reduced violence
levels).




Brian Rodenborn
 
P

pete

osmium said:
I don't know what that means so I won't argue.
(I don't know what "use stdin that way" means. What is 'that'?)

"use the word 'stdin', that way"

It means that they call the standard output stream 'stdin'
even though they define 'stdin' as something else.
 
M

Mike Wahler

pete said:
"use the word 'stdin', that way"

It means that they call the standard output stream 'stdin'

Really, my copy says it's called 'stdout'. :)
even though they define 'stdin' as something else.

What something else? The standard input stream?

-Mike
 
P

pete

Mike said:
What something else? The standard input stream?

I wrote some of that post correctly.
Reread the part that I left quoted above.

Do you think that an expression of type pointer to FILE,
is a stream ?
 
M

Mike Wahler

pete said:
I wrote some of that post correctly.
Reread the part that I left quoted above.

Do you think that an expression of type pointer to FILE,
is a stream ?

I think it's a pointer to a stream, with the stream
abstraction being implemented with type 'FILE'.

-Mike
 
P

pete

Mike said:
I think it's a pointer to a stream,
with the stream abstraction
being implemented with type 'FILE'.

stdin is a pointer to an object.

If stdin were a pointer to a stream, as you say it is,
then stdin still wouldn't be a stream.
 
M

Mike Wahler

pete said:
stdin is a pointer to an object.

... which represents a stream.
If stdin were a pointer to a stream,

It's a macro that expands to a pointer to 'FILE'
as you say it is,
then stdin still wouldn't be a stream.

I didn't say that stdin is or is not a stream.
I would say that the expression 'stdin' *denotes*
a stream, which led to my 'loose' term 'pointer
to a stream'.


7.19 Input/output <stdio.h>

7.19.1 Introduction

1 The header <stdio.h> declares three types, several macros,
and many functions for performing input and output.

2 The types declared are ...

[...]

FILE

which is an object type capable of recording all the
information needed to control a stream, including its
file position indicator, a pointer to its associated
buffer (if any), an error indicator that records whether
a read/write error has occurred, and an end-of-file
indicator that records whether the end of the file has
been reached

[...]

3 The macros are ...

[...]

stderr
stdin
stdout

which are expressions of type "pointer to FILE" that
point to the FILE objects associated, respectively,
with the standard error, input, and output streams.



I don't think calling a 'FILE' an abstraction of a stream
is inaccurate.

But I suppose we're only mincing words here. :)

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top