eck@hound.UUCP (A.ECKBERG) (01/26/84)
Could someone tell me how to download an ASCII null character from unix to my terminal . I need this feature in order to select and download custom characters to my OKIDATA printer. I have an HP terminal. I know how to echo a null character into a file, but it seems that unix filters out null characters during many operations . TED ECKBERG hound!eck
gwyn%brl-vld@sri-unix.UUCP (01/29/84)
From: Doug Gwyn (VLD/VMB) <gwyn@brl-vld> ??? UNIX does not mess around with NULs directed at your terminal (except in some newer versions, it will if you ask it to). Just write( 2, "", 1 ); for example.
clark.wbst@PARC-MAXC.ARPA (01/31/84)
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. --Ray
DBrown.TSDC%hi-multics@sri-unix.UUCP (02/01/84)
This message is empty.
romkey%mit-borax@sri-unix.UUCP (02/01/84)
From: John L. Romkey <romkey@mit-borax> Doing a write(2,"",1) shouldn't write the first byte of your address space! The compiler should cons up a string which consists of a '\0' character and push the address of the string as the second argument in the write. Since the system call was told to write one byte, it'll write a '\0' (or 0 or NULL or whatever you like). - John Romkey romkey@mit-borax
gwyn%brl-vld@sri-unix.UUCP (02/01/84)
From: Doug Gwyn (VLD/VMB) <gwyn@brl-vld> Sorry, write( 2, "", 1 ); is perfectly legal and outputs the NUL end-of-string terminator. Address 0 has nothing whatever to do with this.
sdyer%bbn-unix@sri-unix.UUCP (02/01/84)
From: Steve Dyer <sdyer@bbn-unix> No, Doug is right and you are wrong. write(fh, "", 1) writes an ASCII NUL onto file handle fh. '""' (whew! got that?) resolves to an address of a byte which contains NUL. This is different from write(fh, NULL, 1) or equivalently, write(fh, 0, 1) which writes out the contents of address 0. Does everyone remember what 'setf' looked like on PDP-11 systems? &PNP, Steve Dyer
guy@rlgvax.UUCP (Guy Harris) (02/02/84)
> 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. False. You are probably confusing a null string in C, which is allocated (like all strings) in a program's data space, with the null string that lives, purely by coincidence, at location 0 in some systems' address spaces. Several programs - a lot of them from Berkeley - *depend* on location 0 being a null string; a lot of those programs have been fixed in 4.2 because on the Sun a large and nasty bear trap lives at location 0 and programs which try to dereference null pointers get properly punished. write(2, "", 1); writes one byte from wherever the compiler and linker happened to put the "" mentioned in the call to "write"; that byte would be the first byte of "" which is a zero byte. Why would write(2, "", 1) be any different from write(2, "False statement!\n", 17)? Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy
kfk@ccieng2.UUCP (02/03/84)
---------- 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
clark.wbst@PARC-MAXC.ARPA (02/04/84)
Matt: You are of course right. I goofed. "write(2,"",1) writes the first byte of a zero length string, which should be 0.", as you said. --Ray
ron%brl-vgr@sri-unix.UUCP (02/07/84)
From: Ron Natalie <ron@brl-vgr> Actually it was "setd". p&P6 -Ron