1 /* Division by powers of two.
6 typedef unsigned int UINT
;
8 typedef struct _HeapEntryState
14 static HeapEntryState
*
15 _getHeapEntryState (void *p
, HeapEntryState
*pStates
, UINT nStateEntries
)
17 int uLeft
= -1, uRight
= nStateEntries
, uMiddle
;
19 while (uRight
- uLeft
> 1)
23 uMiddle
= (uLeft
+ uRight
)/2;
24 /* A divide by zero is added just before iDiff is assigned */
25 iDiff
= pStates
[uMiddle
].pBase
- p
;
37 return pStates
+ uMiddle
;
47 HeapEntryState aStates
[] = {
48 { (void __xdata
*)1, 0 }
50 void *p
= (void __xdata
*)0x1234;
52 ASSERT (_getHeapEntryState (p
, aStates
, 1) == NULL
);
55 ASSERT (_getHeapEntryState (p
, aStates
, 1) == aStates
+ 0);