Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!uw-june!uw-entropy!dataio!bright From: bright@dataio.Data-IO.COM (Walter Bright) Newsgroups: comp.lang.c Subject: Re: char (*a)[] (was: Style [++i vs i++]) Message-ID: <1347@dataio.Data-IO.COM> Date: Thu, 13-Aug-87 13:11:49 EDT Article-I.D.: dataio.1347 Posted: Thu Aug 13 13:11:49 1987 Date-Received: Sat, 15-Aug-87 09:55:49 EDT References: <8298@brl-adm.ARPA> <587@cblpe.ATT.COM> <189@xyzzy.UUCP> <1987Aug10.192923.7879@sq.uucp> <234@nvpna1.UUCP> Reply-To: bright@dataio.UUCP (Walter Bright) Organization: Data I/O - FutureNet Corp., Redmond, WA Lines: 35 In article <234@nvpna1.UUCP> strouckn@nvpna1.UUCP (Louis Stroucken 42720) writes: >In article <1987Aug10.192923.7879@sq.uucp> msb@sq.UUCP (Mark Brader) writes: >>Regarding the code... >>> > main(a) >>> > char (*a)[]; > [ discussion wether "a++;" should do something sensible ] >> >>Actually, *declaring* such a pointer is probably illegal. >Please note that "a" is a formal argument of main!! >K&R appendix A section 10.4 says on array arguments: > ...formal parameters declared "array of..." are adjusted to read > "pointer to...". > >The declaration of "a" might as well read "char **a;". "a++;" should >increment "a" with sizeof( char * ) bytes. > >If I miss something, please let me know. I'm letting you know :-) The declaration: char (*a)[]; means: 'a' is a pointer to an array of chars, the size of the array is unknown. Since 'a' is not an "array of...", it is not adjusted to "pointer to..." and is not equivalent to "char **a;". The expression "a++" means "add the size of the array to the pointer 'a'". Since the size of the array is unspecified, the compiler can't do it in any 'unsurprising' way. Therefore, the attempt to do this should be illegal. Expressions of the form (*a)[n] are legal, however, since the compiler does not need to know the size of the array to compile it.