D
Dan Pop
In said:(e-mail address removed) (Dan Pop) writes:
[...]The answer is available in the included text from the standard that is
still visible above: they are physical devices. If they were files,
you could destroy the output you have generated on your monitor with
a remove() function call and reread the user input as many times as you
wanted by closing and reopening the keyboard.
Why do you think the standard *explicitly* talks about two categories of
sources/destinations for I/O operations: physical devices and files
supported on *structured storage devices*?
Whether a device is considered a file is a question about the meaning
of the word "file". The standard doesn't provide an explicit
definition, but it does have wording that clearly implies that a
device can be a file.
In the following, I'll use underscores to denote italics.
C99 7.19.2 p1 says:
Input and output, whether to or from physical devices such as
terminals and tape drives, or whether to or from files supported
on structured storage devices, are mapped into logical data
_streams_, whose properties are more uniform than their various
inputs and outputs.
This makes a clear distinction between physical devices and files on
structured storage devices, but it doesn't quite state that physical
devices are not files. The ambiguity is in the interpretation of the
phrase "files supported on structured storage devices"; does it imply
that *all* files are "supported on structured storage devices", or is
it merely talking about the subset of files that are "supported on
structured storage devices"? Since it doesn't refer to physical
devices as files, it's difficult to tell from this passage alone.
But C99 7.19.3 p1 says:
A stream is associated with an external file (which may be a
physical device) by _opening_ a file, which may involve _creating_
a new file.
That seems pretty clear to me.
The purpose of 7.19.3 p1 is to simplify the wording used in the rest of
section 7.19. We'll pretend from now on that I/O happens to files ONLY,
even if we have already acknowledged that this is not the case.
Feel free to believe that /dev/null is a file on Unix systems, but don't
tell it to other people
A couple of years ago I wrote a Linux device driver for a hardware
watchdog (a device that automatically reboots the system if activated and
then left alone for a certain time). A C program could fopen() it, which
would mean activate it, write to it, which would mean reset the watchdog
timer, and fclose it, which would mean deactivate the watchdog. Read
operations would always fail. Think (hard) about the above described
semantics and see how well they match those of files.
Dan