Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ccieng2.UUCP Path: utzoo!watmath!clyde!floyd!harpo!seismo!rochester!ritcv!ccieng5!ccieng2!kfk From: kfk@ccieng2.UUCP Newsgroups: net.unix Subject: Re: help needed to download ascii null from unix Message-ID: <104@ccieng2.UUCP> Date: Fri, 3-Feb-84 09:59:24 EST Article-I.D.: ccieng2.104 Posted: Fri Feb 3 09:59:24 1984 Date-Received: Wed, 8-Feb-84 08:30:47 EST Organization: Computer Consoles Inc., Rochester, NY Lines: 33 ---------- From: clark.wbst@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