2
I’m facing a small problem with function pointers in a program for Microchip Pic Series 18 microcontrollers.
The code displays the prototypes of two functions involved in the problem and a call to the 'inse_task' function, which SHOULD receive the address of the 'task1' function through the 'task' parameter'.
However, I am debugging the code in Proteus Isis and the 'task' parameter does not receive the address of the function passed as argument. Being more specific, the 'task' parameter receives absolutely nothing.
What am I doing wrong?
void insere_tarefa(uint8 prioridade, tipo_t tipo, void (*tarefa)());
void tarefa1();
insere_tarefa(0, 0, tarefa1);
The printscreen below shows the "value" field of the "task" pointer with no value during the call of the "insert task" function".
Has anyone ever had this kind of problem? How did you solve?
In the codepad the function receives value.
– pmg
@stdio. h a silly doubt. Could you put the implementation of this function? Could you test with the "&"? To get the address, I don’t know will change a lot of things.
– Wakim
@Wakim, I tried using &. It didn’t work. Part of the function implementation appears in the figure above.
– user15528
I mean the impl. of the function passed by parameter.
– Wakim
It’s a test function. It’s just an infinite loop that flashes an LED. The prototype of it is shown in the code snippet I posted with the question.
– user15528
Thanks for your help, but I think the problem is some Proteus bug. I tried to debug the code using the MPLAB X debugger and everything works fine. For some reason Proteus cannot find the address of some functions.
– user15528
Fix the return type of the routine (mostly, don’t forget), as the provavelemte compiler is not finding the correct signature, but not the build error.
– lsalamon
@Isalamon, the return type of the routine is correct. It is a non-return function, and the pointer to the function I set is also void type.
– user15528
In the code Voce posted in the codepad your routine has this: "Return 42;" !!!!
– lsalamon
@Isalamon, who posted that code on the codepad was the pmg.
– user15528