Amiga.org
Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: jahc 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.
-
Typecasting to a generic pointer should do the trick in most cases. Try (void *).
Bye,
Thomas
-
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? :/
-
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
-
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 };