home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!darwin.sura.net!jvnc.net!yale.edu!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.c
- Subject: Re: Why should POINTERS be so damn hard to understand ?
- Date: 27 Aug 1992 15:34:19 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 25
- Message-ID: <17islrINNh6c@early-bird.think.com>
- References: <l9nl34INNhln@almaak.usc.edu> <25233@castle.ed.ac.uk> <1992Aug27.135946.6622@infonode.ingr.com>
- NNTP-Posting-Host: telecaster.think.com
-
- In article <1992Aug27.135946.6622@infonode.ingr.com> henders@infonode.ingr.com (Greg Henderson) writes:
- > int a[1000], *_i;
- > for (_i=a; _i<a+1000; _i++ )
- > *_i = get_some_arbitrary_value();
- >[This] version would not be possible unless you had pointers that
- >knew what type they were supposed to point to, and thus know how many
- >bytes to increment the address to get to next guy.
-
- That's not true. If pointers didn't scale automatically, the programmer
- would do it himself:
-
- int a[1000];
- char *_i;
-
- for (_i=(char *)a; _i<a+1000*sizeof(int); _i+=sizeof(int))
- *(int *)_i = whatever();
-
- I would epect this to produce almost identical code. And in a language
- where pointers weren't typed, you wouldn't need all the casting.
-
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-