Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ucbvax!serge From: serge@ucbvax.UUCP Newsgroups: comp.lang.c++ Subject: Re: ANSI C & C++ idea Message-ID: <17580@ucbvax.BERKELEY.EDU> Date: Fri, 27-Feb-87 00:17:50 EST Article-I.D.: ucbvax.17580 Posted: Fri Feb 27 00:17:50 1987 Date-Received: Sat, 28-Feb-87 08:08:45 EST References: <17516@ucbvax.BERKELEY.EDU> <1857@cit-vax.Caltech.Edu> Reply-To: serge@ucbvax.Berkeley.EDU.UUCP (serge) Distribution: net Organization: University of California at Berkeley Lines: 66 In article <1857@cit-vax.Caltech.Edu> jon@oddhack.UUCP (Jon Leech) writes: >In article <17516@ucbvax.BERKELEY.EDU> serge@ucbvax.BERKELEY.EDU (serge) writes: >> I would like to propose the following notation (valid only in function >>argument declarations/definitions) >> >> void f(return Type *t) >> >>to mean that f() will only write the value pointed to by t, and not read it. > > What's your motivation for doing this? I.e. what kind of >optimizations can a compiler make based solely on knowing that a variable >is 'write-only'? > > One difference I see from 'const' is that the 'const' attribute >may actually be enforced by the hardware as opposed to being a semantic >abstraction. Perhaps MMUs that enforce write-only memory exist (the VAX >doesn't seem to based on a quick perusal of the architecture handbook), >but what do you use it for? The motivation is to provide better type/error checking. For example, one of the more common mistakes in UN*X programming is to pass uninitialized pointers to functions that expect valid addresses, e.g doing (incorrectly) struct stat *s; stat("file", s); instead of struct stat s; stat("file", &s); because the man page declares stat() as extern int stat(const char *file, struct stat *buf); By using the return modifier these kinds of errors can be avoided, by having the compiler make sure that a valid address is passed to a function declared as extern int stat(const char *file, return struct stat *buf); and that a parameter declared as return Type *t or Type *t is written to (a value is assigned to *t) before the function returns, just as a parameter declared as const Type *t is not written to (no assignment to *t occurs). Serge serge@ucbvax.berkeley.edu ...!ucbvax!serge P.S. Note that in C++, the following declaration extern void f(return Type& t) would also be valid.