Dereferencing pointer to incomplete type


 
Thread Tools Search this Thread
Top Forums Programming Dereferencing pointer to incomplete type
# 1  
Old 04-27-2010
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!!!!

Code:
#include<stdio.h>
#include<string.h>
#include<pthread.h>

void *Client(void *);

struct coord{
 	long int x;
	long int y;
	};

struct coord my_coord;

int main()
{
long int i,j;
int rc;

printf("enter the coordinates");
scanf("%ld %ld", &i, &j);

my_coord.x = i;
my_coord.y = j;	

	pthread_t thread;
	rc = pthread_create(&thread,NULL, Client,(void *) &my_coord);
}

void *Client(void * threadarg)
{
	long int xpoint, ypoint;
	struct my_coord *my_point;
	
	my_point = (struct my_coord *) threadarg;
	xpoint = my_point->x;
	ypoint = my_point->y;

	printf("%ld", xpoint);
	printf("%ld", ypoint);
}

# 2  
Old 04-27-2010
I was going to try to get you to code thru your problem, but there were several issues, not just the pointer problem. You HAVE to call pthread_wait in main() or the whole process will exit and the thread may or may not have ever executed Client(). So I just made a few changes and let it go with that.

I removed a bunch of intermediate variables, I left error checking up to you. Check return codes. Always.

Code:
#include<stdio.h>
#include<string.h>
#include<pthread.h>

void *Client(void *);

typedef
struct {
 	long int x;
	long int y;
	} coord_t;


int main()
{
  int rc=0;
  int *p=&rc;
  coord_t my_coord={0,0};
  pthread_t threadid;
  
  printf("enter the coordinates for i & j ");
  scanf("%ld %ld", &my_coord.x, &my_coord.y);
  rc = pthread_create(&threadid, NULL, Client, &my_coord);
  pthread_join(threadid, (void **)&p);
  return 0;
}

void *Client(void * threadarg)
{
	coord_t *p = (coord_t *) threadarg;
	
	printf("%ld ", p->x);
	printf("%ld\n", p->y);
	pthread_exit(0);
}

# 3  
Old 05-12-2010
The basic problem ...

With your code was that you were typecasting wrongly.

I only changed typecasting and did some formatting of output. And yes, do follow the practice of returning a correct value, if your function is prototyped to return something ... The very same thing Jim had adviced you too.

Code:
#include<stdio.h>
#include<string.h>
#include<pthread.h>

void *Client(void *);

struct coord{
        long int x;
        long int y;
        };

struct coord my_coord;

int main()
{
long int i,j;
int rc;


printf("enter the coordinates : ");
scanf("%ld %ld", &i, &j);

my_coord.x = i;
my_coord.y = j;

        pthread_t thread;
        rc = pthread_create(&thread,NULL, Client,(void *) &my_coord);
        pthread_join(thread, NULL);
return 0;
}

void *Client(void * threadarg)
{
        long int xpoint, ypoint;
        struct coord *my_point;

        my_point = (struct coord  *) threadarg;
        xpoint = my_point->x;
        ypoint = my_point->y;

        printf("\n");
        printf("%ld\n", xpoint);
        printf("%ld\n", ypoint);

return NULL;
}



I'd definitely prefer the Jim's version of codes; however this is what you get as your own running code with the minimum amount of edition. Happy coding . Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Warning: pointer type mismatch

Hi all, I'm new programming in C, so I had the next message in my code: Dual.c:88:20: warning: pointer type mismatch in conditional expression : &clientSa.sin6.sin6.sin6_addr, Any help would be great #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include... (1 Reply)
Discussion started by: godna
1 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. Programming

Dereferencing pointer to a shared memory struct

I have what should be a relatively simple program (fadec.c) that maps a struct from an included header file (fadec.h) to a shared memory region, but I’m struggling accessing members in the struct from the pointer returned by shmat. Ultimately, I want to access members in the shared memory structure... (2 Replies)
Discussion started by: arette
2 Replies

4. Programming

gcc 4.3.2 accept sys call warrning incompatible pointer type

Hi all, this warning is driving me nuts. I use -pedantic with -Wall and -Werror so this needs to be fixed. BUILD: GNU-Linux-x86 Any ideas? struct sockaddr_in server_addr; int addr_len = sizeof (server_addr); fd = accept(link->socket_fd, (struct sockaddr_in *)... (2 Replies)
Discussion started by: personificator
2 Replies

5. 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

6. Programming

pass a pointer-to-pointer, or return a pointer?

If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it: (1) one is to pass a pointer-to-pointer parameter, like: int my_malloc(int size, char **pmem) { *pmem=(char *)malloc(size); if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 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

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... (4 Replies)
Discussion started by: boyanov
4 Replies

9. 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

10. 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