Another silly question

Herman Rubin cik at l.cc.purdue.edu
Fri Apr 28 00:17:56 AEST 1989


In article <10135 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
> In article <2459 at nmtsun.nmt.edu> kelly at 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 at l.cc.purdue.edu (Internet, bitnet, UUCP)



More information about the Comp.lang.c mailing list