Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1a 7/7/83; site rlgvax.UUCP Path: utzoo!linus!decvax!harpo!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: mixing pointers and arrays Message-ID: <992@rlgvax.UUCP> Date: Sat, 13-Aug-83 02:23:26 EDT Article-I.D.: rlgvax.992 Posted: Sat Aug 13 02:23:26 1983 Date-Received: Sat, 13-Aug-83 19:27:54 EDT References: <961@rlgvax.UUCP>, <673@watcgl.UUCP>, <1737@allegra.UUCP> Organization: CCI Office Systems Group, Reston, VA Lines: 40 I agree that if you're going to treat structures as (mostly) first-class citizens, you should treat arrays the same way. It would give you a nice way to put "block moves" into code without having to use the USG UNIX 5.0 "memcpy"... routines as a side effect. (If you want to do this you can always declare a structure whose only member is an array, but this is a ghastly kludge). One benefit of structure-valued arguments and returns is that if you want to pass several arguments to a function that are *really* all part of the same data structure, you can do it more cleanly with a structure- valued argument. More importantly, it provides a way to get multiple return values back from a function, which there is no other truly clean way to do (you have to pass pointers to the return values otherwise). One major nuisance with C (and 99% of all programming languages) is that a routine can't return both a value and a status. The "read"/"write" system calls, for example, must either return the number of bytes read/written OR return an "abnormal termination" status - not both. So, you have the problem of trying to have "write" on a magtape say "Well, I wrote all 5120 bytes, but I hit the EOT marker while doing it" or a "write" on a terminal saying "Well, I got 100 of those bytes out before the guy hit the interrupt key". The only way it could be done with only one return value is to have something the convention that "errno" is cleared by all system calls unless there is some abnormal condition; instead of testing for a return value of "-1" (which is also a legitimate return value for some system calls) you test for "errno != 0". An alternative would be to have the return value from a particular system call declared as a structure containing the returned value and the status code. The disadvantage is that some present compilers aren't set up to do them so they don't do them very well. PCC does some strange and non-reentrant things for returning structure values, and the code in the compiler to implement it is painful. Whether this is saying that the architecture of C compilers should not now be the one used for PCC or that C should not be extended to make aggregates first-class citizens is left as a question for posterity to answer (as is the question of how UNIX system calls should indicate abnormal status - note, not all abnormal statuses are really errors, especially with I/O). Guy Harris {seismo,mcnc,we13,brl-bmd,allegra}!rlgvax!guy