error: dereferencing pointer to incomplete type

ccj@ubuntu:~/workspace/process/proconver/shm$ gcc shm1.c -o shm1
shm1.c: In function ‘main’:
shm1.c:46:15: warning: assignment from incompatible pointer type [enabled by default]
shm1.c:47:14: error: dereferencing pointer to incomplete type
shm1.c:50:18: error: dereferencing pointer to incomplete type
shm1.c:52:41: error: dereferencing pointer to incomplete type
shm1.c:54:16: error: dereferencing pointer to incomplete type

shm1.c:55:27: error: dereferencing pointer to incomplete type

这错误一直解决不了,添加了头文件也不行。麻烦各位帮忙下

#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<sys/shm.h>
//#include"shmcom.h"
//#ifndef _SHMCON_H

//#define _SHMCON_H
#define TEXT_SZ 2048

struct shared_use_st {
int written_by_you;
char some_text[TEXT_SZ];
};
//#endif

int main()
{
int running = 1;
void *shared_memory = (void *)0;
struct shared_usr_st *shared_stuff;
int shmid;

srand((unsigned int)getpid());

shmid = shmget((key_t)1244, sizeof(struct shared_use_st), 0666 | IPC_CREAT);
if(shmid == -1)
{
fprintf(stderr, "shmget failed\n");
exit(EXIT_FAILURE);
}

shared_memory = shmat(shmid, (void *)0, 0);
if(shared_memory == (void *)-1)
{
fprintf(stderr, "shmat failed\n");
exit(EXIT_FAILURE);
}

printf("memory attached at %X\n", (int)shared_memory);

shared_stuff = (struct shared_use_st *)shared_memory;
shared_stuff->written_by_you = 0;
  while(running)
   {
   if(shared_stuff->written_by_you)
   {
   printf("you wrote : %s", shared_stuff->some_text);
   sleep(rand() % 4);
   shared_stuff->written_by_you = 0;
   if(strncmp(shared_stuff->some_text, "end", 3) == 0)
   running == 0;
   }
   }
   if(shmdt(shared_memory) == -1)
   {
   fprintf(stderr, "shmdt failed\n");
   exit(EXIT_FAILURE);
   }
   if(shmctl(shmid, IPC_RMID, 0) == -1)
   {
   fprintf(stderr, "shmctl failed\n");
   exit(EXIT_FAILURE);
   }

第1个回答  2014-05-01
void *shared_memory = 0;
shared_use_st *shared_stuff;/////////////

if(strncmp(shared_stuff->some_text, "end", 3) == 0)
    running = 0;//running == 0;

程序没全,没法调。目测两个明显问题,在注释行。

相似回答