我们从2011年坚守至今,只想做存粹的技术论坛。  由于网站在外面,点击附件后要很长世间才弹出下载,请耐心等待,勿重复点击不要用Edge和IE浏览器下载,否则提示不安全下载不了

 找回密码
 立即注册
搜索
查看: 983|回复: 1

静态的声明一个指针变量

[复制链接]

该用户从未签到

3

主题

0

回帖

3

积分

一级逆天

积分
3

社区居民

QQ
发表于 2015-3-2 10:08:09 | 显示全部楼层 |阅读模式
C语言是一门博大精深的语言,我相信没有研读过Linux中代码的人,很少有人体会到吧,废话不多说,简单的写了一个测试demo


test.h
typedef void (* func1_callback)(void);typedef void (* func2_callback)(int i);typedef struct {int size;func1_callback func1_cb;func2_callback func2_cb;} testCallback;typedef struct {int size;int (*init)(testCallback *_tcb);int (*set)(int i);int (*release)(void);} testInterface;
test.c


#include "test.h"#include <stdio.h>testCallback tcb;int test_init(testCallback *_tcb) {printf("This is test init function.\n");tcb = *_tcb;tcb.func1_cb();return 0;}int test_set(int i) {printf("This is test set function, argumaent i is : %d\n", i);tcb.func2_cb(i);return 0;}int test_release(void) {printf("This is test release function.\n");return 0;}static const testInterface tInterface = {.size = sizeof(testInterface),.init = test_init,.set = test_set,.release = test_release,};const testInterface *get_test_interface() {return &tInterface;}
main.c


#include "test.h"#include <stdio.h>void func1_cb() {printf("This is func1 cb, has no argument.\n");}void func2_cb(int i) {printf("This is func2 cb, argument i is : %d\n", i);}testCallback tcb = {sizeof(testCallback),func1_cb,func2_cb,};static const testInterface *ti;int main(void) {ti = get_test_interface();ti->init(&tcb);ti->set(10);ti->release();return 0;}
这个测试demo很简单,不用解释了吧,这篇先这样了。

回复

使用道具 举报

该用户从未签到

168

主题

6352

回帖

923

积分

二级逆天

积分
923

社区居民终身成就奖优秀斑竹奖宣传大使奖社区劳模最爱沙发社区明星灌水天才奖幽默大师奖贴图大师奖新人进步奖忠实会员

发表于 2015-3-2 16:15:16 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

论坛开启做任务可以
额外奖励金币快速赚
积分升级了


Copyright ©2011-2024 NTpcb.com All Right Reserved.  Powered by Discuz! (NTpcb)

本站信息均由会员发表,不代表NTpcb立场,如侵犯了您的权利请发帖投诉

平平安安
TOP
快速回复 返回顶部 返回列表