当前位置:网站首页>C语言回调函数
C语言回调函数
2022-07-26 10:25:00 【青云 --小凡】
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <curl/curl.h>
#include <pthread.h>
#ifdef WIN32
# include <io.h>
# define READ_3RD_ARG unsigned int
#else
# include <unistd.h>
# define READ_3RD_ARG size_t
#endif
#if LIBCURL_VERSION_NUM < 0x070c03
#error "upgrade your libcurl to no less than 7.12.3"
#endif
void* cb(void *arg)
{
printf("call back function, pid=%ld\n", pthread_self());
return NULL;
}
void fun1(void)
{
printf("fun1 call\n");
return;
}
void fun2(int a)
{
printf("fun2 call a=%d\n", a);
return;
}
void fun3(int a, double b)
{
printf("fun3 call a=%d,b=%lf\n", a, b);
return;
}
int fun4(void)
{
printf("fun4 call back\n");
return 666;
}
int* fun5(int a)
{
int* ptr = NULL;
ptr = &a;
printf("fun5 call bacl a=%d\n", a);
return ptr;
}
int main(void)
{
pthread_t therad1;
pthread_create(&therad1, NULL, cb, NULL);
pthread_join(therad1, NULL);
pthread_t thread2;
pthread_create(&thread2, NULL, cb, NULL);
pthread_join(thread2, NULL);
void (*ptr)(void); // ptr是无返回值无参数的函数指针
ptr = fun1;
ptr();
(*ptr)();
void (*ptr2)(int); // ptr2是无返回直带一个参数的函数指针
ptr2 = fun2;
ptr2(666);
void (*ptr3)(int, double);
ptr3 = fun3;
ptr3(12, 234.321);
int (*ptr4)(void);
ptr4 = fun4;
int rtn = ptr4();
printf("rtn=%d\n", rtn);
int* (*ptr5)(int);
ptr5 = fun5;
rtn = *ptr5(888); // ptr5表示int*类型的函数指针,赋值给一个int类型变量需要解引用才可以使用
printf("rtn=%d\n", rtn);
return 0;
}边栏推荐
- Learning about tensorflow (I)
- Learning about opencv (3)
- About the declaration and definition of template functions [easy to understand]
- Closure of go (cumulative sum)
- Strange Towers of Hanoi|汉诺塔4柱问题
- 【Halcon视觉】算子的结构
- string null转空字符串(空字符串是什么意思)
- All codes of Tetris
- Li Kou daily question 917
- 关于函数模板描述错误的是(链接格式错误怎么解决)
猜你喜欢

新建福厦铁路全线贯通 这将给福建沿海带来什么?

PLC概述

Cause: could't make a guess for solution

Review of database -- 1. Overview
![[qualcomm][network] QTI service analysis](/img/76/49054ff8c7215eca98cc479ab1d986.png)
[qualcomm][network] QTI service analysis

Learning about opencv (3)

Learning about tensorflow (II)

The practice of OpenCV -- bank card number recognition

About automatic operation on Web pages

【Halcon视觉】软件编程思路
随机推荐
Data communication foundation telnet remote management equipment
The CLOB field cannot be converted when querying Damon database
[qualcomm][network] QTI service analysis
议程速递 | 7月27日分论坛议程一览
【C#语言】具名类型和匿名类型
string null转空字符串(空字符串是什么意思)
MLX90640 红外热成像仪测温传感器模块开发笔记(六)
Employee information management system based on Web
原生JS-获取transform值 x y z及rotate旋转角度
Network related journals and conferences in CS
[Halcon vision] image gray change
Structure of [Halcon vision] operator
About the declaration and definition of template functions [easy to understand]
关于函数模板描述错误的是(链接格式错误怎么解决)
Necessary for beginners: debug breakpoint debugging skills in idea and common breakpoint skills
新建福厦铁路全线贯通 这将给福建沿海带来什么?
[Halcon vision] programming logic
Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component
【Halcon视觉】图像滤波
The charm of SQL optimization! From 30248s to 0.001s