#
include
<
stdlib.h
>
# include < stdio.h >
typedef int ( * callback)( int , int );
struct st
{
int x;
int y;
callback operate_xy; /*地址,指向函数,占4字节*/
};
int test( int x, int y)
{
printf( "x = %d,y = %d\n" ,x,y);
return 0 ;
}
int main( int argc, char * argv[])
{
struct st * st1 = ( struct st * )malloc( sizeof ( struct st));
st1 - > x = 100 ;
st1 - > y = 200 ;
st1 - > operate_xy = & test;
int * a = ( int * )( & st1 - > operate_xy - 2 );
int * b = ( int * )( & st1 - > operate_xy - 1 );
(st1 - > operate_xy)( * a, * b);/* 指针赋值 */
return 0 ;
}
# include < stdio.h >
typedef int ( * callback)( int , int );
struct st
{
int x;
int y;
callback operate_xy; /*地址,指向函数,占4字节*/
};
int test( int x, int y)
{
printf( "x = %d,y = %d\n" ,x,y);
return 0 ;
}
int main( int argc, char * argv[])
{
struct st * st1 = ( struct st * )malloc( sizeof ( struct st));
st1 - > x = 100 ;
st1 - > y = 200 ;
st1 - > operate_xy = & test;
int * a = ( int * )( & st1 - > operate_xy - 2 );
int * b = ( int * )( & st1 - > operate_xy - 1 );
(st1 - > operate_xy)( * a, * b);/* 指针赋值 */
return 0 ;
}