Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!cmcl2!phri!delftcc!sam From: sam@delftcc.UUCP (Sam Kendall) Newsgroups: net.lang.c Subject: Re: Address of array Message-ID: <139@delftcc.UUCP> Date: Fri, 18-Apr-86 11:47:06 EST Article-I.D.: delftcc.139 Posted: Fri Apr 18 11:47:06 1986 Date-Received: Sun, 20-Apr-86 17:57:41 EST References: <750@abic.UUCP> <211@dg_rtp.UUCP> <685@steinmetz.UUCP> <227@valid.UUCP> Organization: Delft Consulting Corp., New York Lines: 51 Summary: Refutation of arguments against address of array In article <227@valid.UUCP>, sbs@valid.UUCP writes: > When I last left it, the [ANSI] committee was leaning toward allowing &array > so that programmers could portably declare and use thusly: > > typedef int time_t[2]; > ... > time_t t; > printf("%s", (time(&t), ctime(&t))); The point is uniformity of reference, or, more specifically, freeing the programmer from (some) worrying about what type underlies a typedef. In this case, if you want to get a pointer to a variable, you shouldn't have to worry about whether the variable is an array or not, you should just be able to say, for variable `v', `&v'. Total uniformity of reference is impossible for arrays, of course, but allowing address-of-array brings the language a bit closer. > (This objection is rather neatly removed by > > typedef struct { > int once_upon_a[2]; > } time_t; > > but never mind. > ) This won't work for jmp_buf, which must be an array in order to allow calls with the documented syntax, for jmp_buf jb, `setjmp(jb)'. > I lean in the opposite direction (I believe that &array is an undesirable > construct) because of the following gotcha: > > char a[200][40]; > char *b[200]; > ... > strcpy(b[i], a[i]); /* works */ > strcpy(b[i], &a[i]); /* works */ > strcpy(&b[i], &a[i]); /* don't work */ > > Of course, adherents to strong typing will say, "Thou fool. Declare > strcpy(char *, char *) in thy headers," and they're perfectly entitled > to their opinions. No, they'll say, "Use lint, and you will find that only the first strcpy is correct." Lint complains about the last two. Your gotcha is only a gotcha if you don't use lint, in which case there are millions of other gotchas. ---- Sam Kendall { ihnp4 | seismo!cmcl2 }!delftcc!sam Delft Consulting Corp. ARPA: delftcc!sam@NYU.ARPA