home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15290 < prev    next >
Encoding:
Text File  |  1992-09-10  |  2.1 KB  |  52 lines

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