On Friday 04 January 2002 11:38 pm, Gregor N. Purdy wrote:

> You point out a place where I'm trying to resynch pc (which points into
>
> real bytecode) with pc_prederef (which points into the array of void *s):
> > interpreter.c, line 204:
> > ----------------------------
> > static void **
> > prederef(void ** pc_prederef, struct Parrot_Interp * interpreter)
> > {
> >   size_t      offset = pc_prederef - interpreter->prederef_code;
> >   opcode_t *  pc     = ((opcode_t *)interpreter->code->byte_code) +
> > offset;
>
> This is supposed to be calculating offset = # opcodes not # bytes.
> I didn't look it up, and I don't do lots of address arithmetic code,
> but I assumed that pointer differences give offsets that can be passed
> into array indexing / pointer arithmetic to get back where I want. 

Offsets are given in terms of the objects pointed to.  In the above code, 
you've two pointers to pointers, so the byte difference would be offset * 
sizeof(void *).  But then you add that offset to a pointer to an opcode_t, 
so the byte difference would be offset * sizeof(opcode).

I didn't mean to be alarmist - if you've a one-to-one mapping between the 
opcode_t stream and the corresponding void * stream, then you're safe, as 
you're simply scaling the sizes.

But you may want to document that.  It's quite scary looking on first 
glance.  :-)

-- 
Bryan C. Warnock
[EMAIL PROTECTED]

Reply via email to