0
我對c中的結構感到困惑。我正在嘗試創建一個包含我將使用的所有結構的.h文件。我創建structs.hC和.h文件中的結構
#include <ucontext.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct TCB_t;
typedef struct
{
struct TCB_t * next;
struct TCB_t * previous;
ucontext_t context;
int val;
}TCB_t;
我TCB.h文件
#include "structs.h"
int count =0;
struct TCB_t *RunQ = NULL;
struct TCB_t *ptr = NULL;
void init_TCB (struct TCB_t *tcb, void *function, void *stackP, int stack_size, int *arg)
{
memset(tcb, '\0', sizeof(struct TCB_t));
getcontext(&tcb->context);
tcb->context.uc_stack.ss_sp = stackP;
tcb->context.uc_stack.ss_size = (size_t)stack_size;
makecontext(&tcb->context, function, 1, arg);
}
當我跑我得到以下錯誤。
Description Resource Path Location Type
Field 'ss_size' could not be resolved TCB.h /projThree/src line 14 Semantic Error
Description Resource Path Location Type
Field 'ss_sp' could not be resolved TCB.h /projThree/src line 13 Semantic Error
Description Resource Path Location Type
Field 'uc_stack' could not be resolved TCB.h /projThree/src line 13 Semantic Error
Description Resource Path Location Type
Field 'uc_stack' could not be resolved TCB.h /projThree/src line 14 Semantic Error
Description Resource Path Location Type
Symbol 'NULL' could not be resolved TCB.h /projThree/src line 6 Semantic Error
Description Resource Path Location Type
Symbol 'NULL' could not be resolved TCB.h /projThree/src line 7 Semantic Error
如果我將struct fron structs.h移動到TCB.h,錯誤就會消失。爲什麼這個,也不應該TCB.h可以訪問structs.h中的結構體,因爲我在頁面頂部包含了「structs.h」?
函數定義在.h文件中? – Gopi
取決於'structs.h'的位置。也許試試'#include'。另外,函數定義應該放入'.c'文件中。 –
bwinata
我有點困惑。我正在使用c來參加我正在上課的課程。他讓我們使用.h文件中的函數定義 – Aaron