EmbLogic's Blog

ISO C90 forbids mixed declarations and code

make -C /lib/modules/2.6.36.4/build M=/home/zaffer/linux modules
make[1]: Entering directory `/usr/src/linux-2.6.36.4′
CC [M] /home/zaffer/linux/lko.o
/home/zaffer/linux/lko.c: In function ‘start’:
/home/zaffer/linux/lko.c:36:10: warning: ISO C90 forbids mixed declarations and code// WAT IS THE ABOVE LINE?……….//…………#######
Building modules, stage 2.
MODPOST 1 modules
WARNING: “scull_open” [/home/zaffer/linux/lko.ko] undefined!
CC /home/zaffer/linux/lko.mod.o
LD [M] /home/zaffer/linux/lko.ko
make[1]: Leaving directory `/usr/src/linux-2.6.36.4′

HEADER FILE
#include
#include
#include
#include
#include
#include
#include

#define SCULL_MAJOR 0

#define SCULL_MINOR 0

#define device_name “ZAFFER”

#define device_no 1

#define NO_OF_DEVICES 1

#ifndef DEBUG
#define DEBUG
#endif

//………………defining file_operations……………

int scull_open(struct inode*,struct file*);
//int scullrelease(struct inode*, struct file* );

//……………….end of functions…………………..

//…………………….major mainor…………………

static int scull_major = SCULL_MAJOR;
static int scull_minor = SCULL_MINOR;
//………….. ……………………….
//……………….structs and declerations…………..
const struct file_operations fops={
.open = scull_open,
// release: scullrelease
};
struct Scull_dev{

struct cdev cdev;

};
struct Scull_dev *sculldev;

//………………………end of declerations………….
MODULE_AUTHOR(“Zaffer”);
MODULE_LICENSE(“GPL”);
//…………………………………………………..
55,1

LKO.C
int reg;
printk(KERN_INFO “Begin : %s\n”,__func__);
printk(KERN_INFO” HELLO KERNEL”);
printk(KERN_INFO “GREAT”);
if(scull_major)
{
dev=MKDEV(scull_major,scull_minor);
reg=register_chrdev_region(dev,scull_major,device_name);
}
else
{

reg=alloc_chrdev_region(&dev,scull_major,device_no,device_name);
scull_major=MAJOR(dev);
}
if(regcdev.owner=THIS_MODULE;
sculldev->cdev.ops=&fops;
cdev_init(&(sculldev->cdev),&fops );
int scull_open(struct inode *inode, struct file *filp)
{
// #ifdef DEBUG
// printk(KERN_INFO “open function performed sucessfully\n”);
- // #endif
return 0;
}
cdev_add(&(sculldev->cdev),dev,1);
return 0;
}
void __exit release(void)
{
#ifdef DEBUG
printk(KERN_INFO “exit : %s\n”,__func__);
#endif

printk(KERN_INFO “BYE KERNEL”);
unregister_chrdev_region(dev,device_no);
kfree(sculldev);
cdev_del(&(sculldev->cdev));

}

2 Responses to ISO C90 forbids mixed declarations and code

  1. Warning : ISO C90 …. comes when you declare a datatype after or in middle of instructions . so to remove this warning just make sure that in your driver all the local datatype declaration should be at the top of the function .
    Scull_open undefined comes when you mapped your scull_open to open system call but dnt make the body of that particular scull_open function . Check your code for the above correction .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>