Path: utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!alberta!ubc-cs!uw-beaver!mit-eddie!ll-xn!ames!umd5!brl-adm!adm!gay%CLSEPF51.BITNET@CUNYVM.CUNY.EDU From: gay%CLSEPF51.BITNET@CUNYVM.CUNY.EDU (David Gay) Newsgroups: comp.lang.c Subject: RE: sizeof(array) Message-ID: <13001@brl-adm.ARPA> Date: 16 Apr 88 12:00:31 GMT Sender: news@brl-adm.ARPA Lines: 50 In article <259@sdrc.UUCP>, Larry Jones writes: >In article <7684@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA (Doug Gwyn ) writes: >> In article <8646@eleazar.Dartmouth.EDU> major@eleazar.Dartmouth.EDU (Lou > Major) writes: >> >char foo[]="This is a test."; >> >sizeof (foo) == sizeof (char *) >> >> [...] >> >> (I don't think the array name is turned into a pointer just because it's >> surrounded by parentheses.) > >If it ain't, the compiler's broke! The sizeof operator can be applied to a >parenthesized type name or to an expression. Since "foo" isn't a type name, >the operand of sizeof is an expression. When an array name appears in an >expression and it's not the operand of & or sizeof (whose operand is the >parenthesized express, remember), it's converted into a pointer to the first >element. But that isn't what it says; in K&R (1st edition), under the description of sizeof, you see: " [...] When applied to an array, the result is the total number of bytes in the array." [Appendix A, 7.2, p188] I would think that even with the array name surrounded by brackets, sizeof is still being applied to an array. Also, precisely this syntax is used when sizeof is introduced (p126), the statement is #define NKEYS (sizeof(keytab) / sizeof(struct key)) with struct key { ... } keytab[] = { ... }; > >---- >Larry Jones UUCP: uunet!sdrc!scjones >SDRC MAIL: 2000 Eastman Dr., Milford, OH 45150 > AT&T: (513) 576-2070 >"When all else fails, read the directions." Precisely. > David Gay GAY@CLSEPF51.bitnet No one bears a responsability for my opinions.