Yes, within normal code "int (*foo) (CharPtr p)" works fine!

But if I call a function in a shared library, and that function has
a function pointer as a parameter, is the compiler smart enough to
uses a 4 byte function address inside of the shared library instead
the 2 byte function address that all the other functions inside
of the shared library use?

I think at the very least that I'd have to let the compiler know,
when generating the code for the shared library, that the "pointer
to function" needs to be a far pointer not the default near pointer.

Or am I worrying about a triviality???  Does CodeWarrier
automatically make all "pointers to functions" 4 byte addresses, 
even when compiling a single segment, small model, shared library?

My knowledge of assembler is minimal so "LEA *-20,a2" isn't
meaningful, sorry!

Roger Stringer
Marietta Systems, Inc.

----------------------------------------------------------------------

>Subject: Re: Pointers to functions in shared libraries
>From: [EMAIL PROTECTED]
>Date: Tue, 27 Jun 2000 20:42:46 -0700

>> Consequently something like
>>        int (* foo) (CharPtr p)
>> wouldn't work because the compiler (CW5) would view this as a near
>> (2 byte) pointer, not the needed 4 byte pointer.

>Um, why do you think this?  That declaration looks perfectly usable to me.
>Compiling it into a sample bears this out:

>int my_foo (Char* p)
>{
>     return 0;
>}

>UInt32 PilotMain (UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
>{
>     int (* foo) (Char* p);
>
>     foo = my_foo;
>
>     return 0;
>}

>The assignment statement compiles to "LEA *-20,a2", which is exactly what you
>want.

>-- Keith


>>Sent by:  Stringer <[EMAIL PROTECTED]>


>>To:   "Palm Developer Forum" <[email protected]>
>>cc:    (Keith Rollin/US/PALM)
>>Subject:  Pointers to functions in shared libraries

>>I'd like to pass a pointer to an array of pointers to functions as a
>>parameter to a function call to a shared library.
>>(hey, don't you just love working with a computer language where
>>this sentence makes sense!)

>>This would allow the functions within the shared library to call functions
>>back in the main program.

>>Shared libraries use near function addresses (2 bytes), but a far address
>>would be needed to call the functions in the main module.
>>Consequently something like
>>       int (* foo) (CharPtr p)
>>wouldn't work because the compiler (CW5) would view this as a near
>>(2 byte) pointer, not the needed 4 byte pointer.   There may be other
>>issues as well.   I tried "int (far * foo)(CharPtr p)" but the compiler
>>rejected it.

>>Is there a way of specifying pointers to functions as function parameters
>>from a big multi-sector program to a function in a shared library
>>and ensuring the pointers are all correctly sized and formated so the
>>calls can occur?

>>So far I haven't found the right section in the Knowledge Base or any
>>of the manuals.   I suspect it is either really simple or vitually impossible.

>>Roger Stringer
>>Marietta Systems, Inc.



-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to