Dereferencing pointer to incomplete type 
Author Message
 Dereferencing pointer to incomplete type

In my header file I have:

#ifndef __STRINGTABLE__
#define __STRINGTABLE__
typedef struct StringTable *StringTable_ref;
#endif

In my main file I have:

#ifndef  __STRINGTABLE__
#define  __STRINGTABLE__
typedef struct StringTable {
       StringNode_ref   table;
       int              hsize;
       int           elements;

Quote:
} StringTable_ref;

#endif

StringTable_ref new_StringTable( void ) {

     StringTable_ref table1 = malloc(sizeof(StringTable_ref));
     table1->table = malloc(sizeof(StringNode_ref) * 101);
     table1->hsize = 101;
     return table1;

Quote:
}

And I am getting the error:
     Dereferencing pointer to incomplete type

At the lines table1->table... and table1->hsize...

I have been specifically told not to put my structures in my header
file. Any idea what I am doing wrong and what I can do?

Georgie
--



Sat, 20 Aug 2005 02:19:13 GMT  
 Dereferencing pointer to incomplete type
On 03 Mar 2003 18:19:13 GMT,

Quote:
> In my header file I have:

> #ifndef __STRINGTABLE__
> #define __STRINGTABLE__
> typedef struct StringTable *StringTable_ref;
> #endif

That's ok (provided you also have the prototypes for the functions
that use and operate on this type declared in here). This (public)
header file should be included by applications using your API as well
as your implementation file.

Quote:
> In my main file I have:

> #ifndef  __STRINGTABLE__
> #define  __STRINGTABLE__
> typedef struct StringTable {
>        StringNode_ref   table;
>        int              hsize;
>        int           elements;
> } StringTable_ref;
> #endif

Just do

#include "whatever_your_public_header_is_called.h"

struct StringTable {
    StringNode_ref   table;
    int              hsize;
    int           elements;

Quote:
};

Although I would write it as:

struct StringTable {
    struct StringTable table;
    int                hsize;
    int                elements;

Quote:
};

The typedef is defined in the header file, and will therefore be
available here, and the struct itself is defined here, so the rest of
your code below, in this implementation file, will be able to use it.

If you need to have access to the struct's members in more than one
source file, consider using a "private" header file with its
definition.

Martien
--
                        |
Martien Verbruggen      |
Trading Post Australia  | "Mr Kaplan. Paging Mr Kaplan..."
                        |
--



Sat, 20 Aug 2005 13:23:54 GMT  
 Dereferencing pointer to incomplete type

comp.lang.c.moderated:

Quote:
> In my header file I have:

> #ifndef __STRINGTABLE__
> #define __STRINGTABLE__
> typedef struct StringTable *StringTable_ref;
> #endif

This is already bad, symbols (including macros) beginning with two
underscores, or an underscore followed by an upper case letter, are
reserved for the implementation (that is, the compiler and its
headers).  Their use in your header file invokes undefined behavior.

Quote:
> In my main file I have:

> #ifndef  __STRINGTABLE__
> #define  __STRINGTABLE__

I assume, because you do not say, that in your source code file you
include the header file.  In that case, remove the #ifdef around the
definition.  The fact that you have already defined the macro causes
the compiler to skip this definition.

Quote:
> typedef struct StringTable {
>        StringNode_ref   table;
>        int              hsize;
>        int           elements;
> } StringTable_ref;
> #endif

But even if you remove the redundant include guards, you will have
another problem.  In the header file you use typedef to alias the
identifier "StringTable_ref" to a pointer to a struct StringTable.
Then in the source file you try to use typedef to alias the identifier
"StringTable_ref" to mean a struct StringTable, not a pointer to one.

In C it is illegal to typedef the same identifier more than once in a
single scope, although some compilers let it pass if the second
definition is identical to the first.  Perhaps you meant to use
StringNode_ref in the first typedef, the one in the header file?  As
it is, regardless of the incorrect include guards, you haven't defines
the symbol "StringNode_ref" at all, anywhere.

Quote:
> StringTable_ref new_StringTable( void ) {

>      StringTable_ref table1 = malloc(sizeof(StringTable_ref));
>      table1->table = malloc(sizeof(StringNode_ref) * 101);
>      table1->hsize = 101;
>      return table1;

> }

> And I am getting the error:
>      Dereferencing pointer to incomplete type

> At the lines table1->table... and table1->hsize...

> I have been specifically told not to put my structures in my header
> file. Any idea what I am doing wrong and what I can do?

> Georgie

Who told you not to put structure *definitions* in a header file?  If
the structure type is to be used in more than one source file, the
definition of the structure type *absolutely* belongs in a header
file.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
--



Sat, 20 Aug 2005 13:23:58 GMT  
 Dereferencing pointer to incomplete type

Quote:

> In my header file I have:

> #ifndef __STRINGTABLE__
> #define __STRINGTABLE__
> typedef struct StringTable *StringTable_ref;
> #endif

> In my main file I have:

> #ifndef  __STRINGTABLE__
> #define  __STRINGTABLE__
> typedef struct StringTable {
>        StringNode_ref   table;

The real problem is here... you need to say
         StringTable_ref  table;
instead of StringNode

-vish
--



Mon, 22 Aug 2005 13:51:10 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problem with: dereferencing pointer to incomplete type

2. "dereferencing pointer to incomplete type"

3. struct datatype scope (dereferencing pointer to incomplete type)

4. gcc: dereferencing pointer to incomplete type

5. dereferencing pointer to incomplete type

6. dereferencing pointer to incomplete type

7. HELP?! Problem with dereferencing pointer to incomplete type

8. dereferencing pointer to incomplete type

9. dereferencing pointer to incomplete type

10. dereferencing pointer to incomplete type

11. --Dereferencing point to incomplete type

12. type casting to / from pointers to incomplete data types

 

 
Powered by phpBB® Forum Software