Я запутался в structs in c. Я пытаюсь создать файл .h, который имеет все структуры, которые я буду использовать. Я создал structs.hstructs в файлах C и .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 в structs.h, потому что я включил «structs.h» в начало страницы?
Определение функции в файле .h? – Gopi
Зависит от того, где находится 'structs.h'. Возможно, попробуйте '#include'. Кроме того, определения функций должны входить в '.c' файлы. –
bwinata
Я немного смущен. Я использую c для класса, который я принимаю. У нас есть использование определений функций в файлах .h. – Aaron