error: field has incomplete type


 
Thread Tools Search this Thread
Top Forums Programming error: field has incomplete type
# 1  
Old 08-09-2007
Question error: field has incomplete type

Hello there,

Here is how it goes - I have written a small test driver as an exercise to "Linux Device Drivers" and as a preparation for writing a real, functional driver.
For the sake of seeing how far I got it working (I already implemented the open(0, read(), write() and ioctl() calls) I wrote a simple programm which queries some information from the driver:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>       /* mmap() */
#include <fcntl.h>        /* open(), close(), etc. */
#include <unistd.h>       /* exit() */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/cdev.h>

#include "iptimer_ppc_linux26_fnc.h"
#include "iptimer_ppc_linux26_io.h"

int main(int argc, char ** args)
{
      int fd, status = 0;
      unsigned long quantum, qset;
      
      if( (status = open("/dev/iptimer0", O_RDWR)) < 0 ){
            perror("open");
            printf("Error opening /dev/iptimer device file, errno = %d\n", errno);
            exit (1);
      }
      
      if((status = ioctl(fd, IPTIMER_IOCTL_GET_QUANTUM, quantum)) < 0 ){
            perror("ioctl");
            printf("Error getting quantum, errno = %d\n", errno);
            exit (1);
      }
      printf("*** quantum = %d", quantum);

      if((status = ioctl(fd, IPTIMER_IOCTL_GET_QSET, qset)) < 0 ){
            perror("ioctl");
            printf("Error getting qset, errno = %d\n", errno);
            exit (1);
      }
      printf("*** qset = %d", qset);      
      
      return 0;
}

When I try to compile it however, I get the following errors:
Code:
 ~/src/rwtest # make
ppc_60x-gcc -c -o main.o -g main.c
In file included from main.c:13:
iptimer_ppc_linux26_fnc.h:32: error: field `iptimer_cdev' has incomplete type
iptimer_ppc_linux26_fnc.h:33: error: field `iptimer_sem' has incomplete type
make: *** [main.o] Error 1

Here is the struct in which the problem occurs:
Code:
struct iptimer_dev{
      iptimer_qset_t   *iptimer_data;      /* Pointer to first quantum set */
      int                    quantum;            /* The current quantum size */
      int                    qset;               /* The current array size */
      unsigned long int  size;             /* Amount of data stored */
      struct cdev           ptimer_cdev;  /* Char device structure */
      struct semaphore  iptimer_sem;       /* Mutual exclusion semaphore */
      int                       dev_minor;                        
};

So, this two structures of the char dev and the semaphore are defined without "typedef"-s or anithing else in the kernel source. Anyone ahs a clue how to get rid of this errors?
As far as the compilation of the driver itself, everithing goes well.
Here's a link to the actual driver source code, which I wrote.

Any suggestions are welcome. Smilie

_______________________________
Code:
07-08-09 12:41 :( # uname -a
Linux 2.4.21-47.0.1.ELsmp #1 SMP Thu Oct 19 10:46:05 CDT 2006 i686 i686 i386 GNU/Linux
07-08-09 12:52 :( # $CC --version
ppc_60x-gcc (GCC) 3.4.4

# 2  
Old 08-09-2007
Quote:
Originally Posted by boyanov
So, this two structures of the char dev and the semaphore are defined without "typedef"-s or anithing else in the kernel source. Anyone ahs a clue how to get rid of this errors?
A struct does not need a typedef for it to be valid.

Code:
struct a { long x; };

is a valid struct.

You need to:

1. include the file which defines the structs.

2. if you are, then check what #define's control the #ifdefs.
# 3  
Old 08-09-2007
Yes, I include <linux/cdev.h> and <asm/semaphore.h> both in the test program and in my header file.
I found this in the above mentioned headers:
Code:
 #ifndef _LINUX_CDEV_H
 #define _LINUX_CDEV_H
 #ifdef __KERNEL__
 
 struct cdev {
         struct kobject kobj;
         struct module *owner;
         struct file_operations *ops;
         struct list_head list;
         dev_t dev;
         unsigned int count;
 };
...
#endif
#endif

Code:
 #ifdef __KERNEL__
 ...
 #include <asm/atomic.h>
 #include <asm/system.h>
 #include <linux/wait.h>
 #include <linux/rwsem.h>
 
 struct semaphore {
         atomic_t count;
         wait_queue_head_t wait;
 };
...
#endif

Does this mean that I have to wrap my struct definition with the __KERNEL__ define directive? I though it is included by defaul when compiling modules (or maybe it's not for user space apps?).
# 4  
Old 08-09-2007
Are you aware of the terms "user-space" and "kernel-space"?

The macro "__KERNEL__" is being used to give you the appropriate types and sizes for which ever environment your code is being compiled for.

So if you were compiling a driver or kernel module you would have "-D__KERNEL__" as one of your compile options.

A type *may* have a different layout depending on whether it's part of user-space or not, for example the kernel may change considerably without the user-space being affected, so defining __KERNEL__ in a user-space program may not have the affect you want.
# 5  
Old 08-10-2007
OK, I got your point now, my n00b mistake was to include the driver header in my user space program, although I don't really need something defined in it. Nevertheless, a good precausion to such errors in the feature.

Thanks for advising me Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error type order

Hi all, Sample data file... 9f680197||y|a|6 9f6801||6 9f68017|20120511|y|6 9f68017|y|1 9f68017|6 9f68017|20120511|N|2 9f68017|MD|212343907|20120511|N|2 9f68017212343907|20120511|N|2 9f68017N|3 9f68017|20120511|y|3 9f68017|MD|212343907|20120511|N|3 9f68017|MD|212343907|20120511|y|3... (3 Replies)
Discussion started by: bmk
3 Replies

2. Programming

Compilation Error: dereferencing pointer to incomplete type

I am getting a dereferencing pointer to incomplete type error when i compile the following code on lines highlighted in red. Can anyone help me in identifying what is wrong in the code? #include<stdio.h> #include<stdlib.h> typedef struct{ int info; struct node* link ; } node; void... (3 Replies)
Discussion started by: sreeharshasn
3 Replies

3. UNIX for Advanced & Expert Users

find -exec with 2 commands doesn't work (error incomplete staement)

Hi Gurues, I need to modify an existing script that uses find to search a folder, and then move its contents to a folder. What I need to do is run gzip on each file after it's moved. So, I ran this little test: Put a ls.tar file on my $HOME, mkdir tmp, and then: virtuo@tnpmprd01: find .... (3 Replies)
Discussion started by: llagos
3 Replies

4. Red Hat

What type of error is this?

:rolleyes::rolleyes::rolleyes: Jul 18 19:31:31 plbp1s sendmail: STARTTLS: read error=syscall error (-1), errno=104, get_error=error:00000000:lib(0):func(0):reason(0) ---------- Post updated at 03:08 AM ---------- Previous update was at 03:07 AM ---------- # cat /var/log/maillog|egrep -i... (2 Replies)
Discussion started by: manalisharmabe
2 Replies

5. Programming

Dereferencing pointer to incomplete type

// Hello all, I am having this error "Dereferencing pointer to incomplete type " on these 2 lines: xpoint = my_point->x; ypoint = my_point->y; I am having no clue y this is happening. Any help would be greately appreciated!!!! #include<stdio.h> #include<string.h>... (2 Replies)
Discussion started by: mind@work
2 Replies

6. UNIX for Dummies Questions & Answers

Build Error: error: dereferencing pointer to incomplete type

I'm getting the following Error: prepare_pcap.c: In function `prepare_pkts': prepare_pcap.c:127: error: dereferencing pointer to incomplete type prepare_pcap.c:138: error: dereferencing pointer to incomplete type ==================================== This is the part of the relevant... (8 Replies)
Discussion started by: katwala
8 Replies

7. Programming

error: field `fatx_i' has incomplete type

I'm trying to compile a 2.4.26 kernel but I have to apply two patches to it. The patches are: linux-2.4.26-xbox.patch openMosix-2.4.26-1 This is the reason that it doesn't compile. There is only one error but I'm not familiar with C or C++(Unfortunately only Java and some lower-level... (2 Replies)
Discussion started by: lateralus01
2 Replies

8. Programming

array type has incomplete element type

Dear colleagues, One of my friend have a problem with c code. While compiling a c program it displays a message like "array type has incomplete element type". Any body can provide a solution for it. Jaganadh.G (1 Reply)
Discussion started by: jaganadh
1 Replies

9. Programming

Accesing structure member:Error:dereferencing pointer to incomplete type

$ gcc -Wall -Werror struct.c struct.c: In function `main': struct.c:18: error: dereferencing pointer to incomplete type $ cat struct.c #include <stdio.h> #include <stdlib.h> #include <string.h> /*Declaration of structure*/ struct human { char *first; char gender; int age; } man,... (3 Replies)
Discussion started by: amit4g
3 Replies
Login or Register to Ask a Question