tags:

views:

110

answers:

3

is EOF a special byte sequence that lies in the end of every file, or is it kinda exception(interrupt) that is notified by the kernel?

+10  A: 

Long ago on DOS machines it used to be indicated by ^Z, but nowadays it's the kernel reaching the end of the file and notifying the program when it tries to read further.

Ignacio Vazquez-Abrams
The MSDOS `^Z` thing was a hangover from CP/M, where files were always a multiple of 128 bytes long. For text files, the last chunk of 128 bytes was padded with `^Z`s.
spong
^Z is still used in MS-DOS (or Windows command prompt) to mark end of file in text files. This is important to know for example when you are joining binary files with COPY command. You must use the /b flag, otherwise the file is truncated at first ^Z character.
PauliL
+1  A: 

I've used the ASCII EOF character to separate data files into a human-readable header followed by binary data. This allowed everything the mechanical engineers needed from a test to be kept in one file, while keeping it small enough to fit a floppy. (This was years ago!) The EOF character told most text display programs to stop. Anyone wanting a quick peek at the file header could just use a "print" command (is that what it was?) in a command shell.

Mostly these days, the EOF character isn't used in files, at least in the small part of the world I inhabit. Practically none of the ASCII control characters have any use any more, beside NUL, ESC and CR/LF.

EOF may serve some purpose in some streaming protocols, but that's outside my expertise so I leave it to others to address that.

DarenW
just to emphasize one point: in that file format EOF would appear near the start, after a dozen or so lines of text.
DarenW
there's no such thing as EOF in ASCII -- there's ETX (end of text -- ctrl-C) and EOT (end of transmission -- ctrl-D) and EM (end of medium -- ctrl-Y), and even ETB (end of transmitted block -- ctrl-W) but not EOF.
Chris Dodd
A: 

EOF is a special code returned by the C stdio library to denote that there's no more data to be read from a FILE. Different operating systems have their own way of recording the size/end of a file and their own way of returning that to a user program, which will be translated into an EOF return code by the C standard library implementation on that operating system.

Chris Dodd