gpt4 book ai didi

C: 结构 X 没有名为 Y 的成员

转载 作者:行者123 更新时间:2023-11-30 14:26:15 26 4
gpt4 key购买 nike

我正在使用 XINU 操作系统开发一个项目,在向系统添加管道时,在尝试向我之前创建的结构中添加和使用新成员时,出现编译器错误。老实说,我看不出我的代码有什么问题,特别是当我将它与因变量名称而异的工作片段进行比较时。

“/pipcreate.c:21:错误:'struct Pipent'没有名为'owner'的成员”

至于注释掉的两行(reader = PR_CURR,writer = PR_CURR),如果我取消注释它们,并注释掉“owner”行,它确实可以正常编译。

是否有什么问题是显而易见的,而我却完全忽略了它?

管道.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列表来看,似乎没有)。对此的一个简单检查是向 pipeline.h 添加一个明显的语法错误,并查看编译器是否提示它。

关于C: 结构 X 没有名为 Y 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9420653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com