您现在的位置是:智能POS机推广 > 乐刷收银通
pos机参数错误,「粉丝问答25」函数指针定义的一个错误
智能POS机推广2025-04-25 06:36:38【乐刷收银通】0人已围观
简介网上有很多关于pos机参数错误,「粉丝问答25」函数指针定义的一个错误的知识,也有很多人为大家解答关于pos机参数错误的问题,今天乐刷POS机官网(b06.cn)为大家整理了关于这方面的
【温馨提示】如果您有办理pos机的需求或者疑问,可以联系官方微信 18127011016

网上有很多关于pos机参数错误,「粉丝问答25」函数指针定义的参数错误错误一个错误的知识,也有很多人为大家解答关于pos机参数错误的粉丝问题,今天乐刷官方代理商(www.zypos.cn)为大家整理了关于这方面的问答知识,让我们一起来看下吧!
本文目录一览:
1、函数pos机参数错误
pos机参数错误
1. 问题某个函数指针的指针使用:编译时出错了。
type defaults to 'int' in declaration of 'on_touch_messgae_handle'[-Wimplicit-int] typedef(*on_touch_messgae_handle)(touch_message_t);
粉丝源码如下:
2. 分析1) 结构解析1 struct touch_message 2 { 3 rt_uint16_t x; 4 rt_uint16_t y; 5 rt_uint8_t event; 6 }; 7 typedef struct touch_message * touch_message_t; 8 typedef (*on_touch_messgae_handle)(touch_message_t);
首先看下7行这个类型定义:
typedef struct touch_message * touch_message_t;
定义后
touch_message_t
等价于
struct touch_message *
就是定义说我们如果用touch_message_t 定义的变量是一个struct touch_message类型的一个指针。
再来分析下8行这个定义:
typedef (*on_touch_messgae_handle)(touch_message_t);
可以替换成下面这个定义
typedef (*on_touch_messgae_handle)(struct touch_message *);2) 分步解析
有的参数错误错误C语言基础不是很好的朋友,可能无法一眼看出来这个定义,粉丝 为了让新手更容易看懂,问答我们来看一下下面一个递进式的函数定义:
int fun;
这是一个整型变量fun;
int fun();
这是一个函数fun, 参数 : 空 返回值: int型
int fun(struct touch_message *);
这是指针一个函数fun, 参数 : struct touch_message *的定义一个指针 返回值: int型
上述的变化都好理解,下面我们将fun做如下修改:
int (*fun)(struct touch_message *);
括号的参数错误错误优先级最高,(fun)一旦如此定义,粉丝那么fun就要先和结合,问答 所以fun变成了一个指针,
那么该指针指向什么呢? 就需要看外面是如何定义的, 右边是(struct touch_message * ),左边是int, 所以说明指针指向的是一个函数,
参数 : struct touch_message *的一个指针 返回值: int型
举例: 将函数my_fun赋值给函数指针fun。 int my_fun(struct touch_message *) { } int (*fun)(struct touch_message *); fun = my_fun;
这里有一个隐藏的知识点,函数名其实也是一个地址,而且赋值的时候函数类型必须和函数指针类型一致。
typedef int (*fun)(struct touch_message *);
如果左边再加上typedef呢? 相当于是设置fun为新的类型,我们可以用fun来定义一个函数指针, 该函数类型同上。
举例 用新的类型定义一个函数指针变量,并给它赋值。 typedef int (*fun)(struct touch_message *); int my_fun(struct touch_message *) { } fun fun_ptr; fun_ptr = my_fun;
然后将参数修改为,touch_message_t,就得到了粉丝的源码中的样子,
typedef int (*fun)(touch_message_t);
但是粉丝的源码中定义的函数类型缺少了对函数返回值的描述,所以左侧增加一个int或者其他类型即可即可。
3. 函数指针函数指针在linux内核中使用非常频繁,
比如字符设备,内核给多有的字符设备提供了一个统一的接口,我们对设备的所有操作被抽象成read、write、open、close等,并封装到结构体struct file_operations 中:
struct file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); int (*iterate) (struct file *, struct dir_context *); unsigned int (*poll) (struct file *, struct poll_table_struct *); long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); long (*compat_ioctl) (struct file *, unsigned int, unsigned long); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) (struct inode *, struct file *); int (*flush) (struct file *, fl_owner_t id); int (*release) (struct inode *, struct file *); int (*fsync) (struct file *, loff_t, loff_t, int datasync); int (*aio_fsync) (struct kiocb *, int datasync); int (*fasync) (int, struct file *, int); int (*lock) (struct file *, int, struct file_lock *); ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); int (*check_flags)(int); int (*flock) (struct file *, int, struct file_lock *); ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); int (*setlease)(struct file *, long, struct file_lock **); long (*fallocate)(struct file *file, int mode, loff_t offset, loff_t len); int (*show_fdinfo)(struct seq_file *m, struct file *f);};
那么我们应该如何定义该结构体变量并初始化呢?
static struct file_operations hello_ops = { .open = hello_open, .release = hello_release, .read = hello_read, .write = hello_write,};
函数定义如下:
static int hello_open (struct inode *inode, struct file *filep){ return 0;}static int hello_release (struct inode *inode, struct file *filep){ return 0;}static ssize_t hello_read (struct file *filep, char __user *buf, size_t size, loff_t *pos){ return size;}static ssize_t hello_write (struct file *filep, const char __user *buf, size_t size, loff_t *pos){ return size;}
注意,函数的参数和返回值,必须严格按照结构体struct file_operations中的类型定义。
以上就是关于pos机参数错误,「粉丝问答25」函数指针定义的一个错误的知识,后面我们会继续为大家整理关于pos机参数错误的知识,希望能够帮助到大家!
关键词:安全POS机
很赞哦!(4416)
热门文章
热门视频
- https://www.bilibili.com/read/cv40548172/
- https://www.bilibili.com/video/BV1KY63YHEfF/
- https://www.bilibili.com/video/BV1MWk9YLE8U/
- https://www.bilibili.com/opus/1027534315315003394
- https://www.bilibili.com/opus/1013800800888029209
- https://www.bilibili.com/video/BV1NkktYTEkV/
- https://www.bilibili.com/opus/1031967765253062672
- https://space.bilibili.com/37090048/dynamic
- https://www.bilibili.com/video/BV1VvCBY1EnX/
- https://www.bilibili.com/opus/1002593758042128441
站长推荐
全国POS机办理网点
最新标签
- 青岛pos机办理需要多少钱
- 老边区pos机办理需要什么资料
- 安平县pos机办理需要什么资料
- 宜章县pos机代理
- 普定县pos机办理需要注意什么
- 开远pos机正规办理方法
- 贡觉县pos机正规办理方法
- 图们pos机办理需要注意什么
- 定陶县pos机正规办理方法
- 秀峰区pos机正规办理方法
- 长顺县pos机办理需要多少钱
- 崇礼县pos机办理需要注意什么
- 深圳pos机办理中心
- 同安区pos机办理需要什么资料
- 晋安区pos机办理需要多少钱
- 上街区pos机办理需要什么资料
- 钟山区pos机办理需要注意什么
- 睢县pos机办理需要注意什么
- 城子河区pos机办理需要多少钱
- 金沙县pos机正规办理方法
- 德州pos机正规办理方法
- 安源区pos机正规办理方法
- 聂荣县pos机正规办理方法
- 大竹县pos机办理需要什么资料
- 菏泽pos机办理需要什么资料
- 遂昌县pos机办理需要多少钱
- 石嘴山pos机办理需要什么资料
- 漠河县pos机办理需要多少钱
- 定陶县pos机正规办理方法
- 平安县pos机正规办理方法