Chris,

>Date: 17 Sep 1999 11:03:52 -0700
>From: "Chris Antos" <[EMAIL PROTECTED]>
>Subject: constant data table when no globals - how?
>
>i'm using CWR5, and i have a "static const" data table.  unfortunately, it's
>a table of function pointers, so i don't know a way to move it into a
>resource.  this table is referenced by a function that can be called while
>globals are available -- it can also be called while globals are not
>(sysAppLaunchCmdFind).
>
>how can i get this table of constant data to be PC-relative, or to not be
>referenced off of the globals register?  i want the table built at compile
>time, not at run time (which is why i don't want to just remove the "static"
>keyword).
>
>i've looked thru the CWR5 help, and i can't find anything on this.

I believe that newer versions of the CW compiler support PC-relative data
(in addition to PC-relative strings). I haven't tried this with function
pointers, though...the addresses themselves would have to also be
PC-relative, not absolute, so you couldn't use them as regular C-style
function ptrs.

Basically what you're describing is a dispatch table. You could do
something like this, with a bit of work:

typedef struct {
        UInt16  ignoredOpcode;
        Int16   addressOffset;
} JmpInstructionType;

void asm FunctionTable(void)
{
        jmp     Routine1
        jmp     Routine2
        jmp     Routine3
}

void* GetFunctionPtr(UInt16 index)
{
        JmpInstructionType* addrTable = (JmpInstructionType*)FunctionTable;
        UInt8* theAddress = (UInt8*)addrTable;
        theAddress += (index * sizeof(JmpInstructionType))
                + addrTable[index].addressOffset
                + sizeof(UInt16);
        return((void*)theAddress);
}


-- Ken

Ken Krugler
TransPac Software, Inc.
<http://www.transpac.com>
+1 530-470-9200 (direct) +1 408-261-7550 (main)


Reply via email to