Path: utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!tektronix!sequent!mntgfx!tomc From: tomc@mntgfx.mentor.com (Tom Carstensen) Newsgroups: comp.sys.mac.programmer Subject: Pointer arithmetic in C w/ or w/o locked handles Keywords: pointer C arithmetic handles Message-ID: <1988Apr15.125337.100@mntgfx.mentor.com> Date: 15 Apr 88 19:53:34 GMT Organization: Mentor Graphics Corporation, Beaverton Oregon Lines: 39 Is the problem I'm noticing with the following code fragment the compiler, or on error: Handle hdl; char *ptr; long length; HLock(hdl); ptr = *hdl; while ( ) { /* ... stuff here ... */ ptr++; } HUnlock(hdl); length = (long) (ptr - *hdl); Running under The Debugger, I notice that the value for ptr = 80023678, and the value for *hdl = 00023670, and therefore length becomes 80000008, which is actually a negative number. The '8' (or 1000 binary) occurs because it is Locked - (only on 68000 w/ 24 bit addressing). but when I do pointer arithmetic, is the compiler messing up or should I only add Locked handles or Unlocked handles together. If I move the length calculation before I unlock the handle, then length becomes 8, and I'm ok. :------------------------------------------------------------: : Tom Carstensen Usenet: tomc@mntgfx.MENTOR.COM : : Mentor Graphics Delphi: CARSTENSEN : : GEnie: XPC23637 : : : : . . . AAhh! I see you have a machine that goes PING! : : - Monty Python : :------------------------------------------------------------: