1

I have a struct defined as follow:

typedef struct {
    char (*behave) (int*);
} BEHAVIOURSTRUCT;

this struct is defined in a .h file and it is included in the .c file There i have a global variable (MAX_BEHAVIOURS is defined as 3):

BEHAVIOURSTRUCT bhvr[MAX_BEHAVIOURS];

and in the init i try to assign this, but here i get the warning: "assignment from incompatible pointer type"

void init() {
bhvr[0].behave = BHVR_line_follow; // here
...
}

the function i am trying to asign

void BHVR_line_follow(int *currstate){
....
}

by the sound of it my declaration in the struct and the pointer to the function are not from the same build, but in my opinion they are. But most likely i am mistaken.

1 Answer 1

6

Here is your function, and the function-type required, side-by-side:

void BHVR_line_follow(int *currstate)
char (*behave) (int*)

The function-type required takes an int* and returns a char.
Your function takes an int* and returns void (nothing).

To summarize, the return-type of BHVR_line_follow is wrong.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.