Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!husc6!harvard!bunny!ht01 From: ht01@bunny.UUCP (Chen Tu) Newsgroups: net.lang.c Subject: macro to specify output parameter Message-ID: <522@bunny.UUCP> Date: Thu, 14-Aug-86 15:01:51 EDT Article-I.D.: bunny.522 Posted: Thu Aug 14 15:01:51 1986 Date-Received: Thu, 14-Aug-86 21:52:29 EDT Distribution: net Organization: GTE Laboratories, Waltham, MA. Lines: 44 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). To distinguish an output parameter from an array parameter, where both use the '*' notation, I found it is useful to have a macro to replace the notation of the former. #define OUT(name) *name /*** output parameter: ***/ foo(c) char OUT(c); <== output parameter, point to a char. { ... OUT(c) = 'a'; ... } /*** array parameter: ***/ foo(s) char *s; <== input parameter, a character string. { ... *s++ ... } To make the code more readable, do not use the output parameters in other places, and only use OUT(name) on the lhs of assignments, i.e., treat them as OUTPUT ONLY parameters. When the output parameter is also a pointer, we have foo(s) char * OUT(s); { ...; OUT(s) = "this is a test"; ...} compare to foo(s) char **s; { ...; *s = "this is a test"; ...} The former seems more readable and understandable. Another alternative style is: (I have no preference) #define OUT * foo(c) char OUT c; { ...; OUT c = 'a'; ...} Hai-Chen Tu GTE Laboratories Waltham, Mass 02254 (617) 466-4124 CSNET: ht01%gte-labs.csnet