当前位置:网站首页>C language callback function
C language callback function
2022-07-26 10:36:00 【Qingyun -- Xiaofan】
#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 Is a function pointer with no return value and no parameters
ptr = fun1;
ptr();
(*ptr)();
void (*ptr2)(int); // ptr2 Is a function pointer with no return and one parameter
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 Express int* Function pointer of type , Assign to a int Type variables need to be dereferenced before they can be used
printf("rtn=%d\n", rtn);
return 0;
}
边栏推荐
- 事务的传播性propagation
- videojs转canvas暂停、播放、切换视频
- .NET操作Redis Set无序集合
- Draco developed by Google and Pixar supports USD format to accelerate 3D object transmission & lt; Forward & gt;
- STM32 Alibaba cloud mqtt esp8266 at command
- centos8(liunx)部署WTM(ASP.NET 5)使用pgsql
- mysql 进不去了怎么办
- string null转空字符串(空字符串是什么意思)
- 关于函数模板描述错误的是(链接格式错误怎么解决)
- 2022pta平时训练题(1~10题字符串处理问题)
猜你喜欢
Application of.Net open source framework in industrial production
.net5wtm (asp.net core) PgSQL unpacking operation
多目标优化系列1---NSGA2的非支配排序函数的讲解
vscode上使用anaconda(已经配置好环境)
Navicat15 MySQL (centos7) connected to local virtual machine
QRcode二维码(C语言)遇到的问题
SAP ABAP Netweaver 容器化的一些前沿性研究工作分享
Structure of [Halcon vision] operator
2022/07/25 ------ arrangement of strings
[Halcon vision] array
随机推荐
[Halcon vision] threshold segmentation
C语言回调函数
js 获得当前时间,时间与时间戳的转换
Application of.Net open source framework in industrial production
Wechat official account release reminder (wechat official account template message interface)
datav漂亮数据屏制作体验
Database functions
Introduction to Phoenix (Level 1: Phoenix installation, level 2: Phoenix basic grammar)
干货likeshop外卖点餐系统开源啦100%开源无加密
关于函数模板描述错误的是(链接格式错误怎么解决)
Problems encountered in QRcode QR code (C language)
.net5wtm (asp.net core) PgSQL unpacking operation
粽子大战 —— 猜猜谁能赢
2022pta平时训练题(1~10题字符串处理问题)
Write to esp8266 burning brush firmware
[Halcon vision] array
[Halcon vision] image gray change
2022pta usual training questions (1-10 string processing questions)
What if MySQL can't get in
Function template parameters (where are the function parameters)