Welcome, Guest. Please login or register.

Author Topic: function typecast help  (Read 954 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline jahcTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 521
    • Show all replies
    • http://wookiechat.amigarevolution.com
function typecast help
« on: February 21, 2004, 06:15:35 AM »
I dont know how to typecast to "ULONG(*)()".. can someone help me out here?

const struct Hook ConstructLI_TextHook = { { NULL,NULL }, (ULONG*)ConstructLI_TextFunc, NULL,NULL };


8.dh0:MUI/Developer/C/Examples/a> g++ a.cpp
In file included from a.cpp:74:
NList-Demo2.c:109: initialization to `ULONG (*)()' from `ULONG *'

....
I dont know if this helps but heres the Hook function for the code above:

#ifdef __SASC
SAVEDS ASM APTR ConstructLI_TextFunc(REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct NList_ConstructMessage *ncm)
{
#endif
#ifdef __GNUC__
static APTR ConstructLI_TextFunc(void)
{ register Object *a2 __asm("a2");                        Object *obj = a2;
  register struct NList_ConstructMessage *a1 __asm("a1"); struct NList_ConstructMessage *ncm = a1;
  register struct Hook *a0 __asm("a0");                   struct Hook *hook = a0;
#endif

  struct LITD *new_entry = (struct LITD *) AllocVec(sizeof(struct LITD),0);
  if(new_entry)
  { int i = 0, j = 0;
    new_entry->num = -1;
    new_entry->str2 = (char *) ncm->entry;
    while ((j < 3) && new_entry->str2)
    { if ((new_entry->str2 > 'A') && (new_entry->str2 < 'z'))
        new_entry->str1[j++] = new_entry->str2;
      if (new_entry->str2 == '\033')
        i++;
      i++;
    }
    new_entry->str1[j] = '\0';

    return (new_entry);
  }
  return (NULL);
}


Thanks guys.
 

Offline jahcTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 521
    • Show all replies
    • http://wookiechat.amigarevolution.com
Re: function typecast help
« Reply #1 on: February 21, 2004, 06:36:57 PM »
Nope that doesnt work..

In file included from a.cpp:74:
NList-Demo2.c:109: ANSI C++ forbids implicit conversion from `void *' in initialization

-EDIT- (APTR) doesnt work either. Thats what it was set to in the beginning.

any other ideas? :/
 

Offline jahcTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 521
    • Show all replies
    • http://wookiechat.amigarevolution.com
Re: function typecast help
« Reply #2 on: February 22, 2004, 02:12:09 AM »
thanks man, got it sorted now. this is the code that actually got it all working in the end:

ULONG(*testPtr)() = (ULONG(*)())ConstructLI_TextFunc;
const struct Hook ConstructLI_TextHook = { { NULL,NULL }, testPtr, NULL,NULL };

:) took a bit of fiddling. again, thanks for your help.

-EDIT- AHA.. this works too: const struct Hook ConstructLI_TextHook = { { NULL,NULL }, (ULONG(*)())ConstructLI_TextFunc, NULL,NULL };