473,834 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dereferencing pointer to incomplete type

1 New Member
Hello everybody,

I'm writing a game program, and i have compilations errors.. :confused:



Expand|Select|Wrap|Line Numbers
  1. typedef struct
  2. {
  3.     struct lieu* cont;
  4.     struct joueur* j;
  5.     struct creature* c;
  6. }cas;
  7.  
  8. typedef struct
  9. {
  10.     struct cas* grille[N][N];
  11.     int NBL,NBC,i,j;
  12.     struct joueurs* js;
  13. }monde;
  14.  
  15.  
  16. void init_monde(monde* pm)
  17. {
  18. ...
  19.       (*(*pm).grille[i][j]).j=NULL;  <= dereferencing pointer to incomplete type  
  20. ...
  21. }
  22.  
  23.  
can somebody please help me ?? :)
Jul 9 '06 #1
7 51150
D_C
293 Contributor
I had a similar problem earlier, and fixed it by:
Expand|Select|Wrap|Line Numbers
  1. void foo(data* ptr)
  2. {
  3.    data temp = ptr;
  4.    ...
  5. // Do operation(s) on temp
  6.    ...
  7. // Then point ptr to the updated version of itself
  8.    ptr = &temp;
  9. }
I'm not sure if the * and & are in the right places, but let me know if you don't understand the idea.
Jul 10 '06 #2
Strika Amaru
19 New Member
Had the same issue half hour ago; the temporary rid me of "dereferenc ing pointer to incomplete type", but its declaration spits out another error: "storage size of 'tmp' isn't known". Full code:
Expand|Select|Wrap|Line Numbers
  1. typedef unsigned int uint;
  2. typedef struct _Linie{
  3.   char *line;         // 4
  4.   uint length, alloc; // 8
  5.   struct Linie *next, *prev; // 8
  6. }Linie; // =20.
  7.  
  8. void init( struct Linie* linie, uint size ){
  9.   if( linie==NULL ) linie = (struct Linie*)malloc( sizeof( Linie) );
  10.  
  11.   struct Linie l; // <= storage size of 'l' isn't known
  12.   l.line = (char*)malloc( sizeof(char)*size );
  13.   l.alloc = size;  l.length = 0;  l.next = l.prev = NULL;
  14.  
  15.   linie = &l; // works... well, ok, i don't get an error!
  16.   //*linie = l; // I get the "dereferencing..." error again.
  17. }
  18. int main(){
  19.   struct Linie *primul;
  20.   primul = (struct Linie*)malloc( sizeof( Linie) );
  21.   init( primul, 20 );
  22.  // with 'init' commented out, prints the expected 20.
  23.   printf( "\n%d\n", sizeof(Linie) );
  24.   return 0;
  25. }
May 7 '07 #3
Strika Amaru
19 New Member
Teacher solved the issue for me. All I had to do is remove "struct" from the function declaration:
Expand|Select|Wrap|Line Numbers
  1. void init( struct Linie* linie, uint size ){...}
and no more problems.
For the heck of it, I tried removing the temporary entirely:
Expand|Select|Wrap|Line Numbers
  1. void init(Linie* l, uint size ){
  2.   if(l==NULL ) l = (Linie*)malloc( sizeof( Linie) );
  3.   l->line = (char*)malloc( sizeof(char)*size );
  4.   l->alloc = size;
  5.   l->length = 0;
  6.   l->next = l->prev = NULL;
  7. }
Now that works as well...
May 9 '07 #4
dalpine2
1 New Member
Thanks teach!

(this is extraneous text to make the 20 character minimum)
Aug 27 '08 #5
Ganon11
3,652 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1. void init_monde(monde* pm)
  2. {
  3. ...
  4.       (*(*pm).grille[i][j]).j=NULL;// <= dereferencing pointer to incomplete type
  5. ...
  6. }
[/quote]

Not sure, but I think the problem is that the dereference operator (*) takes higher precedence than the member access operator (.) - that is, you should be writing:

Expand|Select|Wrap|Line Numbers
  1. *((*pm).grille[i][j]).j = NULL;
In the code you have, you are trying to dereference *pm, which would be of type monde. Since monde is not a pointer, you can't dereference it.
Aug 28 '08 #6
Banfa
9,065 Recognized Expert Moderator Expert
It should be noted that the use of the temporary variables in all the examples above actually causes the functions to do nothing or at least have rather strange effects depending on presence or not of copy constructors.

The init function of post 4 actually causes a memory leak there is little code in this thread so far of high quality and I would not copy any of it.

The normal resolution of an incomplete type is to include the header defining the type.

Rather than worry about the relative precedences of the dereference operator (*) and member access operator (.) why not just use the member access by pointer operator (->)?
Aug 28 '08 #7
saulgajda
1 New Member
I know it's a bit late, but as it's still on the internet it can help other who look for the right answer.

The problem is with typedef struct {} name; structure.

If you define some type based on structure then you use this defined type WITHOUT struct keyword.

So in the example sent by Vivi I would define monde as:
Expand|Select|Wrap|Line Numbers
  1. typedef struct
  2. {
  3.     struct lieu* cont;
  4.     struct joueur* j;
  5.     struct creature* c;
  6. }cas;
  7.  
  8. typedef struct
  9. {
  10.     cas* grille[N][N]; /* <= changed line */
  11.     int NBL,NBC,i,j;
  12.     struct joueurs* js;
  13. }monde;
  14.  
Btw. I think, that it's good practice to add name to the structure type (since now it's anonymus), just like Strika Amaru did in his piece of code. In this example it would be:
Expand|Select|Wrap|Line Numbers
  1. typedef struct _tagcas /* <= changed */
  2. {
  3.     struct lieu* cont;
  4.     struct joueur* j;
  5.     struct creature* c;
  6. }cas;
  7.  
  8. typedef struct _tagmonde /* <= changed */
  9. {
  10.     cas* grille[N][N]; /* <= or struct _tagcas* ... */
  11.     int NBL,NBC,i,j;
  12.     struct joueurs* js;
  13. }monde;
  14.  
And I agree with Banafa that code below looks much better:
Expand|Select|Wrap|Line Numbers
  1. pm->grille[i][j]->j=NULL;
  2.  
Regards,
Paweł
Aug 20 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
16167
by: Pushkar Pradhan | last post by:
I have some functions which take as i/p a buffer (it can be float, char, or 16 bit, int etc.). The result is another o/p buffer, its type is also flexible (it could be a float, char etc.). I try to pass both as "void *buf" so that it can accept any data type. But since I access the buffer and try to assign its elements to another I get compile errors (I have pasted at the end). Now my question is how can I pass the i/p and o/p buffers...
22
2237
by: Neo | last post by:
Hi Folks, #include<stdio.h> int main() { int (*p); int arr; int i;
204
13149
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 = {0,1,2,4,9};
41
10068
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.55) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed...
5
4156
by: Steven | last post by:
Hello, I get the following message during compilation: `dereferencing pointer to incomplete type' It stems from the compare function I use with qsort() and I am not quite sure how to fix it. I have a struct like: struct node {
8
3867
by: friend.05 | last post by:
I have three files. graph.h: My header file where I have typedef for my structure and function delcaration typedef struct _ipc_actors ipc_graph_actors; typedef ipc_graph_type *ipc_graph_pointer;
4
5238
by: Pritam | last post by:
line 7: error: dereferencing pointer to incomplete type 1. #include<stdio.h> 2. #include<sys/stat.h> 3. #include<stdlib.h> 4. void execname() { 5. struct task_struct *my; 6. my = find_task_by_id(getpid()); 7. printf("%s",my->comm); error: dereferencing pointer to incomplete type
5
3192
by: tejesh | last post by:
I am trying to compile the following code int backend_sm_run(struct interface_data *ctx) { xsup_assert((ctx != NULL), "ctx != NULL", TRUE); xsup_assert((ctx->statemachine != NULL), "ctx->statemachine != NULL", TRUE); backend_sm_check_globals(check);
6
3681
by: hnshashi | last post by:
I have written kernel(2.4) module to communicate with user application using "Netlink Socket". I am getting compilation error "Dereferencing pointer to incomplete type" in kernel module for "nlh = (struct nlmsghdr *) skb->data" line and also not able include "net/sock.h" header file. plz help me how can solve this Thanks
5
9488
by: Anuz | last post by:
Hi all, While compiling a driver, I am getting this error: error: dereferencing pointer to incomplete type int __kc_adapter_clean(struct net_device *netdev, int *budget) { /*some initialization stuff */ struct adapter_struct *adapter = netdev_priv(netdev);
0
9799
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10799
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10554
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9338
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7761
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5629
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3985
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.