C语言我喜欢这样写
来源:互联网 发布:膛线无缝管淘宝有售吗 编辑:程序博客网 时间:2024/06/04 18:32
难呐,活着真难,这个世界什么时候结束,看到那些说喜欢学习的人我就很想打他们,痴线是不是
读书不如抄代码,抄代码不如吃喝玩乐
妈妈总说,要有梦想,阿搭西の梦想就是吃着火锅唱着歌,天天躺着,还有很多钱拿。 是不是很厉害,伟大的梦想。
C语言,C语言, C语言。。。。
阿搭西喜欢这样写,
模块句柄 -> 主进程init获取 -> 其它模块 主进程指针传入
其实我这个写法跟linux内核是一样,作为模块来说,封装好了,一目了然,不管你是单元测试还是干什么几把
主要的意识是这样的:我们尽可能使用static ,我们不要extern
举例子:
a.h
typedef const struct sci2a_pfn
{
void (*__p_sci2a_SendByte)(uint8_t dat);
uint16_t (*__p_sci2a_recive)(void);
uint16_t (*__p_getdata)(uint8_t address);
void (*__p_sci2a_SendByte2)(uint8_t dat);
uint16_t (*__p_sci2a_recive2)(void);
uint16_t (*__p_getdata2)(uint8_t address);
void (*__p_getdistance)(void);
}sci2a_pfn;
typedef struct sci2a_handle
{
sci2a_pfn *pfn;
uint16_t handle_id;
uint16_t touch_sum;
}sci2a_handle;
sci2a_handle* sci2a_init(void);
a.c
static void sci2a_SendByte(uint8_t dat);
static uint16_t sci2a_recive(void);
static uint16_t read_sci2a(uint8_t address);
static void sci2a_SendByte2(uint8_t dat);
static uint16_t sci2a_recive2(void);
static uint16_t read_sci2a2(uint8_t address);
static void getdistance(void);
static sci2a_pfn pfn = {
sci2a_SendByte,
sci2a_recive,
read_sci2a,
sci2a_SendByte2,
sci2a_recive2,
read_sci2a2,
getdistance
};
static sci2a_handle handle = {
&pfn,
};
sci2a_handle* sci2a_init(void)
{
return &handle;
}
main.c
sci2a_handle* __p_sci2a_handle;
__p_sci2a_handle = sci2a_init();
function(__p_sci2a_handle);
__p_sci2a_handle->getdistance();
b.c
void function(sci2a_handle* p_sci2a)
{
......
}
(⊙o⊙)…
感觉好像就是这样了,我这边也没配置层,直接在驱动层定义实体,如果内核的话,probe会从配置层拿到实体的句柄
哎,什么时候才能过吃喝玩乐的日子。。
- C语言我喜欢这样写
- 我喜欢这样实习
- 喜欢你这样叫我~
- 兔子繁殖,我喜欢这样
- 这样的候车室,我喜欢
- 为什么我这样喜欢你
- 我喜欢写CODING
- 我喜欢写博客
- 你为什么要这样喜欢我呢
- C语言原来是这样写的-_-!
- 现在c语言都这样写了么
- 当写C语言写多了,自然就喜欢C++了----小话c++(1)
- 我还是喜欢 C/C++!!!
- 我以C入门,我非常喜欢C语言,望高手们给推荐本好书!
- 我为什么喜欢Go语言
- 我为什么喜欢Go语言
- 我为什么喜欢Go语言
- 我为什么喜欢Go语言
- Ajax的使用
- 关于webstorage的使用
- 应用层--计算机网络自顶向下笔记(二)
- XlistView(代码)
- #再一次用construct2做游戏
- C语言我喜欢这样写
- 垂直居中
- 构造函数和析构函数用法
- 洛谷 P1886 滑动窗口
- java行为设计模式——命令模式
- 数据结构-图的简易实现-C
- 31.Nginx HTTP之请求头解析函数ngx_http_parse_header_line
- R-回归分析
- shell学习整理(10)-函数和参数