Home > other >  Consult to the structure of a function pointer assignment failure problem
Consult to the structure of a function pointer assignment failure problem

Time:10-02

For structure
 struct pin_ops 
{
A) rt_err_t (* (int m, int n);
Rt_err_t (* b) (int m, int n);
};


Define
 struct pin_ops ops=
{
A,
B
};
Struct pin_ops * ops_t;


To structure object ops_t assignment

1) by taking the address of the ops to ops_t assignment
 ops_t=& amp; Ops. Square root 
//this time can be called by ops_t structure functions in the body, such as
Ops_t - & gt; (a);
//)Ops_t - & gt; (b);//square root

Structure of the function can be called successful here,
2) on the function pointer structure carry on assignment
 ops_t - & gt; A=ops - & gt; a; 
Ops - t - & gt; B=ops - & gt; b;
At this time cannot call by ops_t structure functions in the body, such as the following operations are wrong
Ops_t - & gt; (a);//*
Ops_t - & gt; (b);//x

Here even to ops_t allocated memory cannot successful function call, have bosses know what reason be?
In the stm32 calls come into 2) functions in the hard fault in INVSTATE error, refer to know the error because the fault manual kernel attempts to convert the ARM mode lead to mistakes, ask why the kernel here will try to turn the ARM model,

CodePudding user response:

How do you allocate memory allocation, post code

CodePudding user response:

Should not be ops. A and ops. B?
  • Related