Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!uunet!elroy.jpl.nasa.gov!sdd.hp.com!ucsd!pacbell.com!att!linac!mp.cs.niu.edu!ux1.cso.uiuc.edu!news.iastate.edu!IASTATE.EDU!john From: john@IASTATE.EDU (Hascall John Paul) Newsgroups: comp.lang.c Subject: Re: 10[25]==35? Really? Message-ID: <1991Mar1.102108@IASTATE.EDU> Date: 1 Mar 91 16:21:08 GMT References: <25694@netcom.COM> <1991Feb27.223628.13900@unislc.uucp> Sender: news@news.iastate.edu (USENET News System) Reply-To: john@IASTATE.EDU (Hascall John Paul) Organization: Iowa State University Lines: 32 In article <1991Feb27.223628.13900@unislc.uucp>, ttobler@unislc.uucp (Trent Tobler) writes: > From article <25694@netcom.COM>, by avery@netcom.COM (Avery Colter): : : > 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. ((char *)10)[25] and 10[(char *)25] are both perfectly legal, if somewhat unorthodox. I wouldn't go quite as far as "don't do this", but you certainly ought to think hard about it first. One possible example (of course, we all avoid magic numbers in our code ;-) ... #define CSRBASE ((char *)10) /* Starting address of registers */ #define FOOREG 25 /* Foo control is register #25 */ CSRBASE[ FOOREG ] = foo_act_cmd; /* activate foo-o-matic */ -- John Hascall An ill-chosen word is the fool's messenger. Project Vincent Iowa State University Computation Center john@iastate.edu Ames, IA 50011 (515) 294-9551