home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!news!benton.prepress.com!nuntius
- From: chris@benton.prepress.com (christopher m. knox)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Game Techniques (was: NON-QUICKDRAW GAMES)
- Message-ID: <1992Sep10.170549.5552@prepress.com>
- Date: 10 Sep 92 17:05:49 GMT
- References: <1992Sep8.004821.11323@adobe.com>
- <D88-JWA.92Sep9134048@musta.nada.kth.se>
- <D88-JWA.92Sep9192844@cyklop.nada.kth.se> <BuD6qK.7HM@acsu.buffalo.edu>
- Sender: usenet@prepress.com (Usenet login)
- Organization: Pre-Press Technologies, Inc.
- Lines: 36
- Nntp-Posting-Host: chris
- X-Useragent: Nuntius v1.1b2
-
- Subject: Re: Game Techniques (was: NON-QUICKDRAW GAMES)
- From: Nick B Triantos, triantos@acsu.buffalo.edu
- In article <BuD6qK.7HM@acsu.buffalo.edu> Nick B Triantos,
- triantos@acsu.buffalo.edu writes:
- >2. More importantly, from the THINK debugger,
- > offset + base_address (an extern Ptr) + i * 1024
- > moves me to the correct scan line, but I get an error compiling with
- > longPtr assigned to this equation because of a type conflict. But
- if I
- > type cast base_address to (long *) (as done in the code, see PROBLEM
- LINE
- > below), it changes the value of longPtr from being incremented
- 0x0400 to
- > being incremented by 0x1000.
- >
- >PROBLEM LINE: longPtr = offset + (long *)base_address + i * 1024 ;
- > /* 1024=bytes/scan
- line */
-
- Greetings...
- I've grappled with the same problem a few times. In C, if you increment a
- pointer, it gets incremented by the size of the base type e.g.:
- char *pc;
- long *pl;
-
- ++pc; /* gets incremented by 1 byte, since sizeof(char) is 1 byte */
- ++pl; /* gets incremented by 4 bytes, since sizeof(long) is 4 bytes */
-
- this is convenient most of the time but also easy to forget. To fix your
- problem line, change it to: longPtr = (long *) ((long) offset + (long)
- base_address + (long) i * 1024L);
- this performs the calculation as arithmetic rather than pointer
- arithmetic (all the casts
- are not necessary but at least you know exactly what's going on).
- Hope this helps.
- chris knox "Omne animal triste est post (or without) coitum"
-