[mod.std.unix] Counting from 0

std-unix@ut-sally.UUCP (01/28/87)

From: seismo!cmcl2!phri!roy@sally.utexas.edu (Roy Smith)
Date: Sun, 18 Jan 87 09:48:11 est
Organization: Public Health Research Inst. (NY, NY)

[ The square brackets below were apparently inserted by Roy Smith;
they were not added by the moderator.  -mod ]

> From: colonel@sunybcs.UUCP (Col. G. L. Sicherman)
> Now, that [having tail count from 1 instead of 0 is] un-Unixican.
> Characters start at 0, and perhaps blocks and lines should too.  As it
> is, if I want a shell command or expression in the argument, I usually
> have to add 1 to it to make it work.

	While we're it, make "cmp" call the first character in a file 0.
At least on my 4.2BSD system, cmp says the first character in a file is 1.
I would imagine most people only use cmp to test for equality of files, but
I had reason to use the output of "cmp -l" the other day in a shell script
and got burned my this.  Most likely, somebody needs to carefully go
through every command in the book and ferret out count from 0/1 problems.

	Along those lines, what does it mean when some processor says
"error in line 0, file foo"?  On the one hand, it makes computer sense to
call the "first" line/character/block/whatever of a file 0.  On the other
hand, it is very convienent to reserve "error in line 0" to mean "something
went wrong before I even got a chance to start reading the file."
-- 
Roy Smith, {allegra,cmcl2,philabs}!phri!roy
System Administrator, Public Health Research Institute
455 First Avenue, New York, NY 10016

Volume-Number: Volume 9, Number 24

std-unix@ut-sally.UUCP (01/30/87)

From: guy%gorodish@Sun.COM (Guy Harris)
Date: 29 Jan 87 07:12:50 GMT
Reply-To: guy@sun.UUCP (Guy Harris)
Organization: Sun Microsystems, Mountain View

>	While we're it, make "cmp" call the first character in a file 0.
>At least on my 4.2BSD system, cmp says the first character in a file is 1.

"cmp" hasn't changed a lot, so all the other AT&T-derived "cmp"s do
this.

>I would imagine most people only use cmp to test for equality of files, but
>I had reason to use the output of "cmp -l" the other day in a shell script
>and got burned my this.  Most likely, somebody needs to carefully go
>through every command in the book and ferret out count from 0/1 problems.

If people actually use the output of "cmp" in shell scripts, you
can't just "make 'cmp' call the first character in a file 0", since
this may break shell scripts.  You do, however, have to document
whether it calls that byte 0 or 1, and you also have to document
precisely the format of its output, so you *can* use it in shell
scripts.

>	Along those lines, what does it mean when some processor says
>"error in line 0, file foo"?  On the one hand, it makes computer sense to
>call the "first" line/character/block/whatever of a file 0.

For characters and blocks, maybe.  For lines, it may make computer
sense, but not a lot of sense otherwise.  Text editors currently call
the first line line 1, and even people exposed to C for prolonged
periods of time do so as well (probably because their text editor
does...).

>On the other hand, it is very convienent to reserve "error in line 0" to
>mean "something went wrong before I even got a chance to start reading the
>file."

Convenient for the programmer writing the code printing the error
message, maybe, but that doesn't count.  What counts in this case is
convenience to the *user*, and an error message that leaves the line
number out entirely - and even the file name, if the error doesn't
pertain to the file - is far more convenient there.

When some program says "error in line 0, file foo", it generally
means the programmer who wrote that code was too lazy to get the
error message right.

Volume-Number: Volume 9, Number 38