C:struct X没有名为Y的成员
问题描述:
我正在使用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;
}
答
一种可能性是,源文件pipcreat.c
实际上不包括pipe.h
(从图示的#include列表,看来不是)。一个简单的检查就是为pipe.h添加一个明显的语法错误,看看编译器是否抱怨它。
答
所以我认为这个问题是有关的一些对象文件仍然存在后进行更改和编译再次。
基本上我觉得我只需要首先从我的Makefile运行clean,我认为我已经完成了,但也许没有。
答
如果您使用的是gcc,请将-M
选项添加到编译器命令行 - 它会将所有包含的头文件的完整路径吐出。 grep
输出为pipe.h
,你会发现你为什么没有被使用。
答
这是jdk使用的jvmti.h版本的问题。最近版本的jvmti.h中存在但不存在的新方法。
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