首页 > 其他 > 详细

简单使用--函数指针和回调函数

时间:2021-06-13 19:01:39      阅读:14      评论:0      收藏:0      [点我收藏+]
#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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!