Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!mentor.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: Another silly question Summary: Not so silly. I have to work around it. Message-ID: <1266@l.cc.purdue.edu> Date: 27 Apr 89 14:17:56 GMT References: <2459@nmtsun.nmt.edu> <10135@smoke.BRL.MIL> Organization: Purdue University Statistics Department Lines: 26 In article <10135@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) writes: > In article <2459@nmtsun.nmt.edu> kelly@titan.nmt.edu (Sean Kelly) writes: > >He expects that many compilers would instead add the value of i to the > >pointer a, and then reference the item stored there. > > In C, pointer arithmetic ALWAYS involves scaling by the size of the > pointed-to objects. This is one of Dennis's really useful insights. > It is so fundamental to C that I have to worry about an instructor > who claims otherwise. For the same operation, one way will be better on one machine, and a different way on another. There are machines with index operations, where the multiplication by the appropriate power of 2 is invisible hardware, there are machines where increment and decrement for addresses is invisible hardware, and machines where neither of these is the case. I suspect that the number of ways of doing this is comparable to the number of discussants of this on comp.lang.c. Now suppose I am doing some serious array operations, and I have to know whether one array buffer is longer than another. The elements are of type long. Do I have to do this multiplying and dividing by 4 all the time? Another example of "user-friendly" which turns out to be "user-inimical." -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (Internet, bitnet, UUCP)