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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章