voliate类型使用错误
2015-06-18 15:43
232 查看
错误: conflicting types for 'zhgpfdat' previous declaration of 'zhgpfdat' was here
原因:将volatile类型变量的定义和初始化都放在了函数体外
代码示例:
错误代码:
#include <linux/module.h>
#include <linux/kernel.h>
//#include <linux/Kdev.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/io.h>
//#include <linux/ioport.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/uaccess.h>
struct cdev zjled_cdev;
struct class *buttonsclass;
struct device *buttonsclass_dev0;
struct device *buttonsclass_dev1;
struct device *buttonsclass_dev2;
struct device *buttonsclass_dev3;
struct semaphore sem;
volatile unsigned long *zhgpfcon;
volatile unsigned long *zhgpfdat;
zhgpfcon =(volatile unsigned long *)ioremap(0x56000050,16);
zhgpfdat =zhgpfcon+1;
static int __init buttons_init(void)
{
.................................
buttonsclass_dev0=device_create(buttonsclass,NULL,MKDEV(buttons_major,0),NULL,"button0");
buttonsclass_dev1=device_create(buttonsclass,NULL,MKDEV(buttons_major,1),NULL,"button1");
buttonsclass_dev2=device_create(buttonsclass,NULL,MKDEV(buttons_major,2),NULL,"button2");
buttonsclass_dev3=device_create(buttonsclass,NULL,MKDEV(buttons_major,3),NULL,"button3");
.....................................................................
return 0;
}
修正代码:
#include <linux/module.h>
#include <linux/kernel.h>
//#include <linux/Kdev.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/io.h>
//#include <linux/ioport.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/uaccess.h>
struct cdev zjled_cdev;
struct class *buttonsclass;
struct device *buttonsclass_dev0;
struct device *buttonsclass_dev1;
struct device *buttonsclass_dev2;
struct device *buttonsclass_dev3;
struct semaphore sem;
volatile unsigned long *zhgpfcon;
volatile unsigned long *zhgpfdat;
static int __init buttons_init(void)
{
.................................
buttonsclass_dev0=device_create(buttonsclass,NULL,MKDEV(buttons_major,0),NULL,"button0");
buttonsclass_dev1=device_create(buttonsclass,NULL,MKDEV(buttons_major,1),NULL,"button1");
buttonsclass_dev2=device_create(buttonsclass,NULL,MKDEV(buttons_major,2),NULL,"button2");
buttonsclass_dev3=device_create(buttonsclass,NULL,MKDEV(buttons_major,3),NULL,"button3");
zhgpfcon =(volatile unsigned long *)ioremap(0x56000050,16);
zhgpfdat =zhgpfcon+1;
.....................................................................
return 0;
}
原因:将volatile类型变量的定义和初始化都放在了函数体外
代码示例:
错误代码:
#include <linux/module.h>
#include <linux/kernel.h>
//#include <linux/Kdev.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/io.h>
//#include <linux/ioport.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/uaccess.h>
struct cdev zjled_cdev;
struct class *buttonsclass;
struct device *buttonsclass_dev0;
struct device *buttonsclass_dev1;
struct device *buttonsclass_dev2;
struct device *buttonsclass_dev3;
struct semaphore sem;
volatile unsigned long *zhgpfcon;
volatile unsigned long *zhgpfdat;
zhgpfcon =(volatile unsigned long *)ioremap(0x56000050,16);
zhgpfdat =zhgpfcon+1;
static int __init buttons_init(void)
{
.................................
buttonsclass_dev0=device_create(buttonsclass,NULL,MKDEV(buttons_major,0),NULL,"button0");
buttonsclass_dev1=device_create(buttonsclass,NULL,MKDEV(buttons_major,1),NULL,"button1");
buttonsclass_dev2=device_create(buttonsclass,NULL,MKDEV(buttons_major,2),NULL,"button2");
buttonsclass_dev3=device_create(buttonsclass,NULL,MKDEV(buttons_major,3),NULL,"button3");
.....................................................................
return 0;
}
修正代码:
#include <linux/module.h>
#include <linux/kernel.h>
//#include <linux/Kdev.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/io.h>
//#include <linux/ioport.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/uaccess.h>
struct cdev zjled_cdev;
struct class *buttonsclass;
struct device *buttonsclass_dev0;
struct device *buttonsclass_dev1;
struct device *buttonsclass_dev2;
struct device *buttonsclass_dev3;
struct semaphore sem;
volatile unsigned long *zhgpfcon;
volatile unsigned long *zhgpfdat;
static int __init buttons_init(void)
{
.................................
buttonsclass_dev0=device_create(buttonsclass,NULL,MKDEV(buttons_major,0),NULL,"button0");
buttonsclass_dev1=device_create(buttonsclass,NULL,MKDEV(buttons_major,1),NULL,"button1");
buttonsclass_dev2=device_create(buttonsclass,NULL,MKDEV(buttons_major,2),NULL,"button2");
buttonsclass_dev3=device_create(buttonsclass,NULL,MKDEV(buttons_major,3),NULL,"button3");
zhgpfcon =(volatile unsigned long *)ioremap(0x56000050,16);
zhgpfdat =zhgpfcon+1;
.....................................................................
return 0;
}
相关文章推荐
- java基础将字符串进行反转
- Codeforces #272 Div 1 简要题解
- [PHP] 图像二次渲染
- 【iframe与父页面重合】
- 垂直搜索引擎中的分词系统
- switch case
- 在C#中使用C++编写的类1
- C#调用函数传参数IEnumerable<ClassA> classlist.ToList(),不会改变classlist
- SqlServer查询同一张表中多个字段相同的记录
- CAD控件:COM接口实现自定义实体的方法
- 第6章 C控制语句:循环
- iframe参数
- Path相关评论的方法(一)
- map结构初探
- 在onDestroy方法中做处理要小心
- iscsi网络存储
- LintCode PlusOne 加一
- 【测试实验】stm32 usart 前导符,空闲符号,断开符号
- Zookeeper 05 示例代码-主备节点切换
- html img热区坐标根据屏幕大小自适应