0

私のファイルの1つ(変更は許可されていないと言われた)で、次のエラーが発生し続けます。

In file included from buffer.h:1,
             from buffer.c:4:
semaphore.h:4: error: expected specifier-qualifier-list before ‘st_cond_t’

ライブラリを追加するst.hと、コンパイルされて正常に実行されますが、このファイルを変更することは許可されていないと言われたため、回避する方法を見つける必要があり、方法がわかりません。助言がありますか?以下に関連するコードを掲載します。

semaphore.h: このファイルの編集は許可されていません

typedef struct
{
  int value;
  st_cond_t sem_queue;
} semaphore;

void down(semaphore *s);
void up(semaphore *s);
void createSem(semaphore *s, int value);

buffer.h

#include "semaphore.h"
#include "st.h"
#pragma once //necessary to avoid compiler errors

/*this file just defines the structure of a buffer and the methods that will be associated with it. Not too complex */

typedef struct
{
    semaphore *emptyBuffer; //need two semaphores according to slides
    semaphore *fullBuffer;
    int nextIn;
    int nextOut;
    int size;
    char *chars; //literall buffer object
}buffer;

void c_deposit(buffer *buffer, int c); //declaring our functions, similar to an interface in java
int c_remove(buffer *buffer);

buffer *init_buffer(int size);

buffer.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "buffer.h"
#include "st.h"

/* This file fleshes out the methods declared in the header. c_deposit/c_remove are identical in logic to the slides for this assignment, they follow the basic consumer/producer dynamic. init_buffer initializes and provides memory for the elements associated with a buffer struct so that we can access them later */

//prototypes
void c_deposit(buffer *buffer, int c);
int c_remove(buffer *buffer);

buffer *init_buffer(int size);

void c_deposit(buffer *buffer, int c) //code pretty much taken from slides
{
    down(buffer->emptyBuffer); //called down semaphore
    buffer->chars[buffer->nextIn]=c; //put char on char buffer
    buffer->nextIn=(buffer->nextIn+1)%buffer->size; //increment counter
    up(buffer->fullBuffer); //call up semaphore
}
int c_remove(buffer *buffer) //almost identical to deposit
{
    int c;
    down(buffer->fullBuffer);
    c=buffer->chars[buffer->nextOut]; //pull off char
    buffer->nextOut=(buffer->nextOut+1)%buffer->size; //increment
    up(buffer->emptyBuffer);
    return c; //return char
}
buffer *init_buffer(int size) //initializing components of our buffer
{
    //want to malloc so that we don't lose it when we return
    buffer *new_Buffer;
    new_Buffer=malloc((sizeof(buffer)));

    semaphore *sem; //malloc a semaphore and then set the buffer empty/full semaphores equal to it so don't lose it
    sem=malloc(sizeof(semaphore));

    new_Buffer->emptyBuffer=sem; //same as last comment
    createSem(new_Buffer->emptyBuffer, size); //have to create the semaphore

    semaphore *sem2;
    sem2=malloc(sizeof(semaphore));

    new_Buffer->fullBuffer=sem2;
    createSem(new_Buffer->fullBuffer, 0);

    char *array; //malloc for the char buffer
    array=malloc(sizeof(char)*size);
    new_Buffer->chars=array;

    new_Buffer->size=size;

    int nextIn=0; //initialize the basic ints
    new_Buffer->nextIn=nextIn;

    int nextOut=0;
    new_Buffer->nextOut=nextOut;

    return new_Buffer;
}

main.c: 参照用に #include セクションをインクルードするだけです

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "st.h"
#include "buffer.h"
4

1 に答える 1