dereferencing pointer to incomplete type

Hey Guys,

Below is the code

glob.h
1
2
3
4
5
6
#ifndef GLOB_H
#define GLOB_H
const int LEN=10;
struct myStruct;
struct myStruct *head;
#endif 


temp.c
1
2
3
4
5
6
7
8
9
10
11
#include "glob.h"

struct myStruct {
  char arr[LEN];
  struct myStruct *next;
};

struct myStruct *head = NULL; 

void someFunction() { // this function creates the linked list of myStruct
                      // and *head is the head node 
}


test.c
1
2
3
4
5
6
7
8
9
10
11
12
#include "glob.h"

void testFunction() { 

 // from here I am calling someFunction() to create the Linked List 

}

void printFunction() {

 // here I am trying to print the list using *head in glob.h 
}


The compilation error I am getting is dereferencing pointer to incomplete type

Please guide me through

Thanks


Last edited on
Why do you not declare the struct in glob.h?

Also, you should not declare variables in header files. That will not give you what you want.
Wow, that is so weird. Last night I tried to define struct in my header file and it was complaining about the fact that I had an array size declared in struct. Today, it is working. I was definitely doing something else wrong. Anyways, jsmith, could you please tell me the better way to achieve this. What I am trying to do is,

I want to create a linked list in one file, and access it in another file. That's why I am declaring the struct and head pointer in glob.h

Please let me know the better way to do this

Thanks
Topic archived. No new replies allowed.