我正在使用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;
}
BTW您沒有爲piptr分配任何空間。 – Avi 2012-02-23 20:29:56
pipcreate.c不包含pipe.h,至少不是直接。 – 2012-02-23 20:30:51
讓你的編譯器生成預處理輸出,然後檢查你是否真的使用了你自己定義的'struct pipent'。 – jamesdlin 2012-02-23 20:30:55