LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-07-2005, 05:04 AM   #1
mp4-10
LQ Newbie
 
Registered: Jan 2005
Posts: 16

Rep: Reputation: 0
file_operations structure


HI,
I am writing chardev driver and get int troubles while compiling module with gcc -c modulename.c.
Error reported from compiler is: error:
chardev.c 255:variable `fops' has initializer but incomplete type
chardev.c:257: warning: excess elements in struct initializer
chardev.c:257: warning: (near initialization for `fops')
chardev.c:258: warning: excess elements in struct initializer
chardev.c:258: warning: (near initialization for `fops')
chardev.c:259: warning: excess elements in struct initializer
chardev.c:259: warning: (near initialization for `fops')
chardev.c:260: warning: excess elements in struct initializer
chardev.c:260: warning: (near initialization for `fops')
chardev.c:261: warning: excess elements in struct initializer
chardev.c:261: warning: (near initialization for `fops')
chardev.c:262: warning: excess elements in struct initializer
chardev.c:262: warning: (near initialization for `fops')
chardev.c:263: warning: excess elements in struct initializer
chardev.c:263: warning: (near initialization for `fops')
chardev.c:264: warning: excess elements in struct initializer
chardev.c:264: warning: (near initialization for `fops')
chardev.c:265: warning: excess elements in struct initializer
chardev.c:265: warning: (near initialization for `fops')
chardev.c:266: warning: excess elements in struct initializer
chardev.c:266: warning: (near initialization for `fops')
chardev.c:267: warning: excess elements in struct initializer
chardev.c:267: warning: (near initialization for `fops')
chardev.c:268: warning: excess elements in struct initializer
chardev.c:268: warning: (near initialization for `fops')
chardev.c:269: warning: excess elements in struct initializer
chardev.c:269: warning: (near initialization for `fops')
chardev.c:270: warning: excess elements in struct initializer
chardev.c:270: warning: (near initialization for `fops')
chardev.c:271: warning: excess elements in struct initializer
chardev.c:271: warning: (near initialization for `fops')
chardev.c:273: warning: excess elements in struct initializer
chardev.c:273: warning: (near initialization for `fops')
chardev.c:255: error: storage size of `fops' isn't known

source code:
static struct file_operations fops={
NULL,
NULL,
device_read,
device_write,
NULL,
NULL,
device_ioctl,
NULL,
device_open,
NULL,
device_release
};

Bye
 
Old 02-07-2005, 10:03 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
What's the point of the NULLs? That's not valid C syntax.
 
Old 02-07-2005, 06:03 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
You also need to declare the types for each var ...
 
Old 02-08-2005, 02:32 AM   #4
AngryLlama
Member
 
Registered: Sep 2004
Location: /dev/urandom
Distribution: Gentoo
Posts: 171

Rep: Reputation: 30
Since file_operations has so many unused fields I usually choose to use the explicit syntax:

Code:
static struct file_operations fops = {
        .read = vfd_read,
        .write = vfd_write,
        .open = vfd_open,
        .release = vfd_release,
        .ioctl = vfd_ioctl
};
Concidering you use NULL, I assume you are an ex-windows programmer. If you insist on keeping NULL then add a:
Code:
#ifndef NULL
#define NULL (0)
#endif
if you are using plain C then ((void*)0) is a safer define.

bye
 
Old 02-08-2005, 09:26 AM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Quote:
Originally posted by AngryLlama

Concidering you use NULL, I assume you are an ex-windows programmer. If you insist on keeping NULL then add a:
Code:
#ifndef NULL
#define NULL (0)
#endif
if you are using plain C then ((void*)0) is a safer define.

bye
From linux/stddef.h on a Slackware 10 box.

Code:
#undef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif
I've found that #including any standard header like iostream, etc. will make it so that NULL is defined for you. Nothing "ex-windows" about it.

Last edited by deiussum; 02-08-2005 at 09:28 AM.
 
Old 02-08-2005, 01:53 PM   #6
AngryLlama
Member
 
Registered: Sep 2004
Location: /dev/urandom
Distribution: Gentoo
Posts: 171

Rep: Reputation: 30
oh, well I didn't think NULL was a part of the C specification. However, it does not surprise me it is defined by default. And by ex-windows I figured he is a seasoned Windows programmer because of how much Windows uses NULL in it's api
 
Old 10-28-2009, 03:50 AM   #7
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,634
Blog Entries: 29

Rep: Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900
"chardev.c 255:variable `fops' has initializer but incomplete type"

This error points out that you have not included "linux/fs.h" !

"gcc -c modulename.c"

You cant compile a kernel module with gcc you need to write a makefile for it !

Last edited by TheIndependentAquarius; 10-28-2009 at 03:52 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory Structure fedix Linux - Newbie 3 10-14-2005 03:48 PM
structure os2 Programming 6 05-29-2005 08:39 PM
Filesystem structure Techformer Linux - Newbie 3 11-29-2004 04:35 PM
error with structure rubinbob Programming 2 07-21-2004 08:55 AM
What is the Organizational Structure of LQ? yadavankur LQ Suggestions & Feedback 5 11-23-2002 09:11 PM


All times are GMT -5. The time now is 01:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration