Pointers to Functions

Asked

Viewed 129 times

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?

debug

  • In the codepad the function receives value.

  • 1

    @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, I tried using &. It didn’t work. Part of the function implementation appears in the figure above.

  • I mean the impl. of the function passed by parameter.

  • 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.

  • 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.

  • 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.

  • @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.

  • In the code Voce posted in the codepad your routine has this: "Return 42;" !!!!

  • @Isalamon, who posted that code on the codepad was the pmg.

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.