voliate类型使用错误

错误: 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值