Hello everybody,
I'm writing a game program, and i have compilations errors.. :confused: - typedef struct
-
{
-
struct lieu* cont;
-
struct joueur* j;
-
struct creature* c;
-
}cas;
-
-
typedef struct
-
{
-
struct cas* grille[N][N];
-
int NBL,NBC,i,j;
-
struct joueurs* js;
-
}monde;
-
-
-
void init_monde(monde* pm)
-
{
-
...
-
(*(*pm).grille[i][j]).j=NULL; <= dereferencing pointer to incomplete type
-
...
-
}
-
-
can somebody please help me ?? :)
7 51150 D_C 293
Contributor
I had a similar problem earlier, and fixed it by: - void foo(data* ptr)
-
{
-
data temp = ptr;
-
...
-
// Do operation(s) on temp
-
...
-
// Then point ptr to the updated version of itself
-
ptr = &temp;
-
}
I'm not sure if the * and & are in the right places, but let me know if you don't understand the idea.
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: - typedef unsigned int uint;
-
typedef struct _Linie{
-
char *line; // 4
-
uint length, alloc; // 8
-
struct Linie *next, *prev; // 8
-
}Linie; // =20.
-
-
void init( struct Linie* linie, uint size ){
-
if( linie==NULL ) linie = (struct Linie*)malloc( sizeof( Linie) );
-
-
struct Linie l; // <= storage size of 'l' isn't known
-
l.line = (char*)malloc( sizeof(char)*size );
-
l.alloc = size; l.length = 0; l.next = l.prev = NULL;
-
-
linie = &l; // works... well, ok, i don't get an error!
-
//*linie = l; // I get the "dereferencing..." error again.
-
}
-
int main(){
-
struct Linie *primul;
-
primul = (struct Linie*)malloc( sizeof( Linie) );
-
init( primul, 20 );
-
// with 'init' commented out, prints the expected 20.
-
printf( "\n%d\n", sizeof(Linie) );
-
return 0;
-
}
Teacher solved the issue for me. All I had to do is remove "struct" from the function declaration: - void init( struct Linie* linie, uint size ){...}
and no more problems.
For the heck of it, I tried removing the temporary entirely: - void init(Linie* l, uint size ){
-
if(l==NULL ) l = (Linie*)malloc( sizeof( Linie) );
-
l->line = (char*)malloc( sizeof(char)*size );
-
l->alloc = size;
-
l->length = 0;
-
l->next = l->prev = NULL;
-
}
Now that works as well...
Thanks teach!
(this is extraneous text to make the 20 character minimum)
Ganon11 3,652
Recognized Expert Specialist - void init_monde(monde* pm)
-
{
-
...
-
(*(*pm).grille[i][j]).j=NULL;// <= dereferencing pointer to incomplete type
-
...
-
}
[/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: - *((*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.
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 (->)?
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: -
typedef struct
-
{
-
struct lieu* cont;
-
struct joueur* j;
-
struct creature* c;
-
}cas;
-
-
typedef struct
-
{
-
cas* grille[N][N]; /* <= changed line */
-
int NBL,NBC,i,j;
-
struct joueurs* js;
-
}monde;
-
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: -
typedef struct _tagcas /* <= changed */
-
{
-
struct lieu* cont;
-
struct joueur* j;
-
struct creature* c;
-
}cas;
-
-
typedef struct _tagmonde /* <= changed */
-
{
-
cas* grille[N][N]; /* <= or struct _tagcas* ... */
-
int NBL,NBC,i,j;
-
struct joueurs* js;
-
}monde;
-
And I agree with Banafa that code below looks much better: -
pm->grille[i][j]->j=NULL;
-
Regards,
Paweł
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
by: Neo |
last post by:
Hi Folks,
#include<stdio.h>
int main()
{
int (*p);
int arr;
int i;
|
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};
|
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...
|
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 {
| |
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;
|
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
|
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);
|
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
|
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);
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |