help needed to download ascii null from unix

kfk at ccieng2.UUCP kfk at ccieng2.UUCP
Sat Feb 4 00:59:24 AEST 1984


----------
	From: clark.wbst at PARC-MAXC.ARPA
	Subject: Re: help needed to download ascii null from unix

	Uh, write(2,"",1) writes the first byte of your address space, which may
	be zero if you are lucky.  I remember a long discussion a while ago on
	the subject of *0 and what is found there.  I don't remember the outcome
	or positions, but I don't think it is a particularly swift idea in general.
----------
This is wrong on two points.  First, write (2, "", 1) does *not* write the first
byte of the address space.  There has been discussion on constant strings in
net.unix-wizards for a bit now on the subject of just what a constant string
really is.  Someone pointed out from an authoritative source that a constant
string is of type 'array of char,' with storage class 'static.'  Thus, "" is an
array of 1 character, and that one character has a '\0' in it.  (Remember that
C strings end with a null byte.)  Writing this byte is a perfectly reasonable
thing to do.  The fundamental problem with the previous explanation was that
the concept of a null string was confused with a null pointer.  A valid pointer
can indeed point to a null string (i.e., a string with only 1 zero byte in it).

Second, *0 is highly suspect, to say the very least.  For some reason which
escapes me completely, on some machines you can dereference a null pointer
(i.e., 0) and get something reasonable.  However, on most machines, this is
invalid.  In particular, the M68000 will reward the user of such techniques
with a segmentation fault and a core dump.  There is *ABSOLUTELY NOTHING*
at location 0 that can be accessed by a program.  The definitive sources
(Kernighan & Ritchie, and the ANSI proposed C standard) state in unequivocal
terms that 0 may be assigned as a pointer value, and it is *guaranteed* that
this pointer will then point to *no usable data*.  Do not, repeat DO NOT,
*ever* write code which tries to do this.
-- 
Karl Kleinpaste
...![ [seismo, allegra]!rochester!ritcv, rlgvax]!ccieng5!ccieng2!kfk



More information about the Comp.unix mailing list