您的位置:首页 > 其它

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: