Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!topaz!nike!lll-crg!lll-lcc!pyramid!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.lang.c Subject: Re: macro to specify output parameter Message-ID: <6229@sun.uucp> Date: Fri, 15-Aug-86 18:58:37 EDT Article-I.D.: sun.6229 Posted: Fri Aug 15 18:58:37 1986 Date-Received: Sun, 17-Aug-86 07:32:38 EDT References: <522@bunny.UUCP> Distribution: net Organization: Sun Microsystems, Inc. Lines: 53 > When I read C functions, many times I was confused about the roles > played by their parameters: it is hard to tell a pointer > parameter is an array or a pointer to a scaler (to be used as an > output parameter). Well, actually, pointer parameters are never arrays; arrays and pointers are two completely different things. This may be a good argument for allowing "&" to be applied to arrays (yielding a pointer value of type "pointer to array of ", NOT type "pointer to "!) and using "pointer to array" as the argument type if you really want to pass a pointer to the array. Of course, in the second example routine "foo", it may not really be a pointer to the first element of an array/string; that routine might be used to stuff characters into some arbitrary place in a string, so it's not really a pointer to a string/array, it's just a pointer to a "char" that is assumed to be somewhere within a string/array. This may, in fact, also be an argument for reference types a la C++; there, your routine "foo" would be written as foo(c) char &c; { ... c = 'a'; /* store 'a' in the "char" referred to by "c" */ ... } This is how call-by-reference is done in C++; in other languages that implement call-by-reference, output parameters are generally passed by reference. Your second proposed style comes close to implementing this as best as can be done in C. Try #define REF * /* for defining reference types */ #define DEREF * /* dereferencing operator; since C doesn't know about reference types, it won't automatically dereference them */ foo(c) char REF c; { ... DEREF c = 'a'; ... } -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com (or guy@sun.arpa)