首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C:结构X没有名为Y的成员

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

Stack Overflow用户
提问于 2012-02-24 04:23:07
回答 4查看 9.6K关注 0票数 0

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

"/pipcreate.c:21:错误:'struct pipent‘没有名为’owner‘的成员“

至于被注释掉的两行代码(reader = PR_CURR,writer = PR_CURR),如果我取消对这两行代码的注释,并注释掉'owner‘行,它确实编译得很好。

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

pipe.h

代码语言:javascript
复制
/*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

代码语言:javascript
复制
#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;
}
EN

回答 4

Stack Overflow用户

发布于 2012-02-24 04:29:26

一种可能是源文件pipcreat.c实际上并没有包含pipe.h (从显示的#include列表中看起来没有)。一个简单的检查方法是在pipe.h中添加一个明显的语法错误,并查看编译器是否对此提出了抱怨。

票数 1
EN

Stack Overflow用户

发布于 2012-02-24 16:47:12

如果您使用的是gcc,请在编译器命令行中添加-M选项-它将显示包含的所有头文件的完整路径。对pipe.h的输出执行grep命令,您就会发现为什么没有使用您的输出。

票数 1
EN

Stack Overflow用户

发布于 2012-02-24 16:28:52

所以我认为这个问题与一些目标文件在修改和重新编译后仍然存在有关。

基本上,我认为我必须首先从Makefile运行干净,我认为我已经做到了,但也许不是。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9420653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档