Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!viusys!uxui!unislc!ttobler From: ttobler@unislc.uucp (Trent Tobler) Newsgroups: comp.lang.c Subject: Re: 10[25]==35? Really? Message-ID: <1991Feb27.223628.13900@unislc.uucp> Date: 27 Feb 91 22:36:28 GMT References: <25694@netcom.COM> Organization: unisys Lines: 22 From article <25694@netcom.COM>, by avery@netcom.COM (Avery Colter): > With all this about the #define X1 -10, I find it interesting that > indexing a constant yields the sum of the constant and the number inside > the brackets. > > I could RTFM till the cows come home and never would have gleaned this. No, RTFM again. The definition of x[y] is not (x+y); it is *(x+y). So, 10[25] is *(10 + 25) which is illegal, since only pointers can be dereferenced. > > Silly me, I would have thought that 10[25] would yield the value > residing in the position 25 positions away from address 10. Not unless you do something like ((char *) 10)[25], which, depending on how the compiler treats this, may do what you thought it would. BTW, don't do this. --- Trent Tobler - ttobler@csulx.weber.edu