I have a C function declared as "CreateTask(void (*) void, int*, int, int)"
and is called from my program as "CreateTask(Task, &TaskStack,1,1)"
where "Task" is defined as "void Task(void)"
However, I get an error which states that they are of incompatible types from type 'void function' to type 'void generic* function (void)' during compilation. Could someone please advise why this error exist as I have not encountered this problem when I use the Turbo C compiler but only now when I switch to SDCC 'C' Compiler.
Thank you in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I guess, the quotes around C indicate you believe SDCC to be less of C compiler than Turbo C. In this case that is not so. What you have written is not ANSI-C. Your function prototype should have been declared as:
CreateTask(void(*)(void), int*, int, int);
And what I consider to be even better:
CreateTask(void(*pFunc)(void), int* pStack, int i, int j);
Or even typedef the function pointer first:
typedef void (*pVoidFunc)(void);
CreateTask(pVoidFunc pFunc, int* pStack, int i, int j);
Hope this helps,
Maarten
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
according to sdcc's error message : "from type 'void function' to type 'void generic* function (void)'" the definition of CreateTask() is sufficiently correct, as sdcc understands what you mean - even if it is not ANSI-C.
The call "CreateTask(Task, &TaskStack,1,1);" causes the problem, as it is passed the function as the first parameter ... which makes no sense.
It should read: "CreateTask(&Task, &TaskStack,1,1)" - this way a _pointer_ to the function is passed.
sdcc is a bit 'picky' - no offense meant- about function pointers. So when calling a function via a function pointer you need to explicitly de-reference it:
int (*write)(int, void*, int);
len = (*(write))(fcb->ucb->number, dat, size);
other compilers also accept:
len = write(fcb->ucb->number, dat, size);
regards,
Karsten.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, so now I've tried my suggested code and the first one still fails. Apparently SDCC agrees with me that you better insert names for the parameters you're describing in the prototype. Both the second and third compile OK, though.
SDCC does not care if you take the address of the function or not. It produces the exact same code for it.
Greets,
Maarten
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I have a C function declared as "CreateTask(void (*) void, int*, int, int)"
and is called from my program as "CreateTask(Task, &TaskStack,1,1)"
where "Task" is defined as "void Task(void)"
However, I get an error which states that they are of incompatible types from type 'void function' to type 'void generic* function (void)' during compilation. Could someone please advise why this error exist as I have not encountered this problem when I use the Turbo C compiler but only now when I switch to SDCC 'C' Compiler.
Thank you in advance.
Hello Wilson,
I guess, the quotes around C indicate you believe SDCC to be less of C compiler than Turbo C. In this case that is not so. What you have written is not ANSI-C. Your function prototype should have been declared as:
CreateTask(void(*)(void), int*, int, int);
And what I consider to be even better:
CreateTask(void(*pFunc)(void), int* pStack, int i, int j);
Or even typedef the function pointer first:
typedef void (*pVoidFunc)(void);
CreateTask(pVoidFunc pFunc, int* pStack, int i, int j);
Hope this helps,
Maarten
Hello,
according to sdcc's error message : "from type 'void function' to type 'void generic* function (void)'" the definition of CreateTask() is sufficiently correct, as sdcc understands what you mean - even if it is not ANSI-C.
The call "CreateTask(Task, &TaskStack,1,1);" causes the problem, as it is passed the function as the first parameter ... which makes no sense.
It should read: "CreateTask(&Task, &TaskStack,1,1)" - this way a _pointer_ to the function is passed.
sdcc is a bit 'picky' - no offense meant- about function pointers. So when calling a function via a function pointer you need to explicitly de-reference it:
int (*write)(int, void*, int);
len = (*(write))(fcb->ucb->number, dat, size);
other compilers also accept:
len = write(fcb->ucb->number, dat, size);
regards,
Karsten.
Hello Karsten,
Ok, so now I've tried my suggested code and the first one still fails. Apparently SDCC agrees with me that you better insert names for the parameters you're describing in the prototype. Both the second and third compile OK, though.
SDCC does not care if you take the address of the function or not. It produces the exact same code for it.
Greets,
Maarten