Welcome, Guest. Please login or register.

Author Topic: function typecast help  (Read 959 times)

Description:

0 Members and 2 Guests are viewing this topic.

Offline Noster

  • Sr. Member
  • ****
  • Join Date: Jan 2004
  • Posts: 375
    • Show all replies
Re: function typecast help
« on: February 21, 2004, 09:30:35 PM »
Hi

First of all, why don't you deklare your hook function in the desired type ?

#ifdef __SASC
SAVEDS ASM ULONG ConstructLI_TextFunc(REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct NList_ConstructMessage *ncm)
{
#endif
#ifdef __GNUC__
static ULONG ConstructLI_TextFunc(void)
...


Second, if you wish to cast a function-pointer, you must also specify all arguments like this:

APTR foobar (ULONG arg1, UBYTE arg2)
{
   /* This function expects two arguments and returns an APTR.
    */
   APTR result;

   /* Do anything with the arguments and 'result'...
    */
...

  return result;
}

void f ()
{
   /* This function want's to cast a pointer to the function "foobar" defined above
    * to a function pointer that expects a different returnvalue.
    */
   ULONG(*fctptr)(ULONG,UBYTE);   /* this is a functionpointer */

   /* Now we cast a pointer to "foobar" to the type required for the function pointer:
    */
   fctPtr = (ULONG(*)(ULONG,UBYTE)foobar;

   /* That's it, now you could call "foobar" using the function pointer 'fctptr'...
    */
...

   Noster
DON\\\'T PANIC
    Douglas Adams - Hitch Hiker\\\'s Guide to the Galaxis