Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!lll-lcc!ames!orville!fouts From: fouts@orville.UUCP Newsgroups: comp.arch Subject: Re: Available no. of registers Message-ID: <213@ames.UUCP> Date: Sun, 25-Jan-87 00:41:12 EST Article-I.D.: ames.213 Posted: Sun Jan 25 00:41:12 1987 Date-Received: Sun, 25-Jan-87 06:19:14 EST References: <3810002@nucsrl.UUCP> <926@mips.UUCP> <759@vaxb.calgary.UUCP> <1029@cuuxb.UUCP> <763@vaxb.calgary.UUCP> Sender: usenet@ames.UUCP Reply-To: fouts@orville.UUCP (Marty Fouts) Lines: 59 In article <763@vaxb.calgary.UUCP> radford@calgary.UUCP (Radford Neal) writes: >I know C is poorly designed, but is it really THIS bad?! Did Kernighan and >Ritchie suffer from this level of brain damage? Does anyone know? > A pointer points to an address in memory. manipulating items at offsets from that address by using that pointer is just fine. A common valid use is to set a char pointer to the first character in a string and then increment the pointer to examine succesive characters. There is nothing in the language that requires the programmer to stop at the end of the string. . . >I assume the proposed ANSI standard doesn't countenance this sort of >behaviour... > Of course it does. A classic use of the above idiom (sort of from K&R, but by memory, I don't have my copy handy is: char *s; char *t = "a string"; . . . while (*s++ = *t++) ; . . . To copy the string pointed to by t to the memory pointed to starting at the place where s originaly points. >Anyway, regardless of what old C manuals said, this is sufficiently >ridiculous programming that compiler writers should ignore it and >shoot any programmers who complain. Actually it would be quite difficult to allow C constructs such as those above will prohibiting illegal references through pointers, but this isn't suprising; even ADA can't protect you from misusing a pointer reference. The magic in C is that any kind of pointer can be assigned the address of any kind of data, provided that the data has an address (lvalue in K&R) via the classic cast: Some_kind X; Other_kind *Y ; Y = (Other_kind *) &X; This is used heavily in C. The semantics of many Un*x kernels and more than a few applications programs would break without it. The problem occurs when you do pointer arithmetic on Y. It is perfectly legitimate to write: X = *(Some_kind *) (Y+1); and get at whatever is one Sizeof(Other_kind) beyon the original X in memory. Of course, if pointers have the same "shape," it becomes possible to leave out the type casts, making the code difficult to port.