2012-02-23 104 views
0

我正在使用XINU OS進行項目工作,並在向系統中添加管道時嘗試向我之前創建的結構添加和使用新成員時出現編譯器錯誤。 我真的不能看到我的代碼出了什麼問題,特別是當我將它與工作件因變量名而異時。C:struct X沒有名爲Y的成員

「/pipcreate.c:21:錯誤:‘結構pipent’沒有名爲構件‘所有者’」

至於註釋掉兩行(讀者= PR_CURR,作家= PR_CURR)如果我去掉那些,並註釋掉「所有者」這一行,它編譯得很好。

有沒有什麼突出的問題是明顯的,我完全忽略了它?

pipe.h

/*typedef int32 pipid32 inside of kernel.h*/ 

/* Max number of pipes in the system */ 
#ifndef NPIP 
#define NPIP 10 
#endif 

/* Pipe state constants */ 

#define PIPE_FREE 0 /* pipe table entry is unused */ 
#define PIPE_USED 1 /* pipe is currently used */ 
#define PIPE_CONNECTED 2 /* pipe is currently connected */ 

/* Misc pipe definitions */ 

#define isbadpipid(x) (((pid32)(x) < 0) || \ 
      ((pid32)(x) >= NPIP) || \ 
      (piptab[(x)].pipstate == PIPE_FREE)) 

/* Definition of pipe table */ 

struct pipent {   /* entry in the pipe table */ 
uint32 pipstate; /* pipe state: PIP_FREE, ect. */ 
uint32 pipid;  /* pipe ID in table   */ 
char buffer[256]; /* buffer to write to  */ 
pid32 writer;  /* pid for writer  */ 
pid32 reader;  /* pid for reader  */ 
pid32 owner;  /* CURR_PID upon pipe being created */ 
}; 

extern struct pipent piptab[]; 
extern int32 pipcount; 

pipcreate.c

#include <xinu.h> 
#include <string.h> 

static pipid32 newpipid(void); 
/*------------------------------------------------------------------------ 
* pipcreate - 
*------------------------------------------------------------------------ 
*/ 
syscall pipcreate(void){ 
    intmask mask;  /* saved interrupt mask */ 

//struct pipent piptab[]; 
struct pipent *piptr;  /* ptr to pipe's table entry */ 
pipid32 pipid;    /* ID of newly created pipe */ 

mask = disable(); 

pipid = newpipid();   /* pipid to return */ 
piptr->pipstate = PIPE_USED; 
piptr->owner = PR_CURR; 
    //piptr->writer = PR_CURR; 
    //piptr->reader = PR_CURR; 

pipcount++;     /* increment number of pipes */ 
piptr = &piptab[pipid]; 

restore(mask); 
return pipid; 
} 

//newpipid - obtain a new (free) pipe ID 
local pipid32 newpipid(void) 
{ 
uint32 i; 
static pipid32 nextpipid = 1; 
/* Check all NPIP slots */ 
for(i = 0; i < NPIP; i++){ 
    nextpipid %= NPIP; /* wrap around to beginning */ 
    if(piptab[nextpipid].pipstate == PIPE_FREE){ 
     return nextpipid++; 
    } else { 
     nextpipid++; 
    } 
} 
return (pid32) SYSERR; 
} 
+0

BTW您沒有爲piptr分配任何空間。 – Avi 2012-02-23 20:29:56

+0

pipcreate.c不包含pipe.h,至少不是直接。 – 2012-02-23 20:30:51

+0

讓你的編譯器生成預處理輸出,然後檢查你是否真的使用了你自己定義的'struct pipent'。 – jamesdlin 2012-02-23 20:30:55

回答

1

一種可能性是,源文件pipcreat.c實際上不包括pipe.h(從圖示的#include列表,看來不是)。一個簡單的檢查就是爲pipe.h添加一個明顯的語法錯誤,看看編譯器是否抱怨它。

0

所以我認爲這個問題是有關的一些對象文件仍然存在後進行更改和編譯再次。

基本上我覺得我只需要首先從我的Makefile運行clean,我認爲我已經完成了,但也許沒有。

1

如果您使用的是gcc,請將-M選項添加到編譯器命令行 - 它會將所有包含的頭文件的完整路徑吐出。 grep輸出爲pipe.h,你會發現你爲什麼沒有被使用。

0

這是jdk使用的jvmti.h版本的問題。最近版本的jvmti.h中存在但不存在的新方法。