Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!mcnc!rti!xyzzy!throopw From: throopw@xyzzy.UUCP (Wayne A. Throop) Newsgroups: comp.lang.c Subject: Re: char (*a)[] (was: Style [++i vs i++]) Message-ID: <196@xyzzy.UUCP> Date: Thu, 13-Aug-87 09:51:48 EDT Article-I.D.: xyzzy.196 Posted: Thu Aug 13 09:51:48 1987 Date-Received: Sat, 15-Aug-87 10:42:52 EDT References: <8298@brl-adm.ARPA> <587@cblpe.ATT.COM> <189@xyzzy.UUCP> <1987Aug10.192923.7879@sq.uucp> Organization: Data General, RTP NC. Lines: 48 > msb@sq.uucp (Mark Brader), >> throopw@xyzzy.UUCP >>> main(a) >>> char (*a)[]; >>> { a = 0; printf("a=0x%x\n", a); a++; printf("a=0x%x\n", a); } >> the program is illegal for >> the obvious reason that it increments a pointer to an object of unknown >> size, > Actually, *declaring* such a pointer is probably illegal. True. Draft X3J11 limits arrays of unknown size to formals and externals. In my opinion, this is wrong. >> but *also* because it performs arithmetic on a null pointer, and >> of course, this is illegal. > Um, I don't think so, Wayne; it's just that the result, if you indirect > through such a pointer, is undefined. K&R is silent on this, but ANSI > 3.3.6 seems pretty clear. Yes indeed. Pretty clear: For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to an object and the other shall have integral type. I repeat: "pointer to an object". The null pointer doesn't qualify. Further, K&R are not totally silent on this point either. I quote from 7.4 in the reference: A pointer to an object in an array and a value of any integral type may be added. K&R therefore can be considered to be even *more* restrictive, since they call out that the object must be a member of an array. (Actually, I think draft X3J11 calls this out also, but this result must be peiced together from several readings of Holy Writ, and I don't want to be thought to be in competition with The World Tomorrow TV show.) > The OTHER thing that's wrong with the code is that a "%x" format is used > to print a pointer variable. [...] > On an ANSI compiler, you would write: > printf ("a=%p\n", (void *) a); > and be guaranteed reasonable results. But I don't think "%p" exists yet. Good point. -- IBM manuals are written by little old ladies in Poughkeepsie who are instructed to say nothing specific. --- R. T. Lillington