#include <unistd.h>
#include<stdio.h>
//要求在run函数里面每隔一秒运行一个函数,这个函数由main.c指定(函数放在main.c里面)
void (*__handle)(void) = NULL; //定义函数指针
void run(){
int cn = 0;
while (1)
{
if( __handle ){
__handle();
}else{
printf( "step NOT running... \n") ;
}
cn++;
sleep(2);
}
}
#include<stdio.h>
#include "run.c"
void (*__handle)(void) ;
void step_cb(void){
printf( "step_cb running... \n") ;
}
int main(){
printf( "hello... \n") ;
__handle = step_cb;
// step = NULL;
run();
return 0;
}
输出:
原文:https://www.cnblogs.com/fll0601/p/14880209.html