home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!ames!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: 28 Aug 1992 15:03:03 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 24
- Message-ID: <17lf77INN3nk@early-bird.think.com>
- References: <1992Aug27.135946.6622@infonode.ingr.com> <17islrINNh6c@early-bird.think.com> <1992Aug27.181844.11739@email.tuwien.ac.at>
- NNTP-Posting-Host: telecaster.think.com
-
- In article <1992Aug27.181844.11739@email.tuwien.ac.at> hp@vmars.tuwien.ac.at (Peter Holzer) writes:
- >barmar@think.com (Barry Margolin) writes:
- >>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.
- >You would still have to cast _i to (int *), or the compiler couldn't
- >know how much memory it should access (1 byte? 1 word? ...)
-
- Declaring pointers doesn't allocate memory.
-
- >Anyway, why should I type sizeof(int), when the compiler can do it for
- >me?
-
- Several people seem to have misunderstood the point of my posting. I'm not
- recommending the above code. I was just showing how you would do it if C
- didn't have this feature. I was responding to a post that said that typed
- pointers are *necessary* to be able to step a pointer through an array.
-
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-