home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!newsserver.pixel.kodak.com!psinntp!psinntp!rlyeh.multisys.com!rot
- From: rot@multisys.com (Republic of Taiwan)
- Subject: Re: Why should POINTERS be so damn hard to understand ?
- Message-ID: <Btx3II.Fyn@multisys.com>
- Organization: Multimedia Information Systems Corporation, San Jose, CA TEL: (408) 437-3031 E-mail: info@multisys.com
- References: <25233@castle.ed.ac.uk> <1992Aug27.135946.6622@infonode.ingr.com> <1992Aug28.163724.11581@mccc.edu>
- Date: Tue, 1 Sep 1992 20:56:41 GMT
- Lines: 42
-
- In article <1992Aug28.163724.11581@mccc.edu> pjh@mccc.edu (Pete Holsberg) writes:
- =In article <1992Aug27.135946.6622@infonode.ingr.com> henders@infonode.ingr.com (Greg Henderson) writes:
- ==Well one reason that pops to mind is the nice ability to use a pointer
- ==to traverse an array more efficently than the 'normal' way. For ex...
- ==
- ==You could do this normally:
- =={
- == int a[1000], i;
- ==
- == for ( i=0; i<1000; i++ )
- == a[i] = get_some_arbitrary_value();
- ==}
- ==
- ==Or you could do this w/ a pointer:
- =={
- == int a[1000], *_i;
- ==
- == for (_i=a; _i<a+1000; _i++ )
- == *_i = get_some_arbitrary_value();
- ==}
- ==
- ==These two pieces of code do the exact same thing, but if you are
- ==worried about low-level efficiency the second version is a little
- ==tighter, as each reference to the array value in the pointer version
- ==requires less work to come up w/ that address.
-
- The presumption here is that the length of int is same as
- the length of the address space.
-
- If the int is 4 byte long and the address space is 2(or 8 or 3) byte long,
- the this fell miserably. The second one is not portable.
-
- =
- =Isn't that a function of the compiler? In fact, let me ask why don't we
- =have compilers that produce the most efficient code even when array
- =notation is used? Is it that they would be too slow? I recall a FORTRAN
- =compiler for a 16-bit digital computer used in a hybrid computer system
- =back in the 60s that produced wonderful code, but took a very very long
- =time to do it.
- =
-
-
-