What is the right way to write this code?
I want to make a circular buffer that will receive as a parameter a pointer to some type of data. This way I wrote not working. I have problem with circular_buf_put function. It says invalid use of void expression. error: invalid use of void expression cb->data[cb->head]=data;
What is right way to use it here?
typedef struct circular_buf{
void *data;
size_t tail;
size_t head;
size_t capacity;
size_t objectSize;
size_t size;
} circular_buf;
int circular_buf_init(struct circular_buf *cb, void *data, size_t objectSize, size_t capacity)
{
cb->data=data;
cb->objectSize=objectSize;
cb->capacity=capacity;
cb->tail=0;
cb->head=0;
cb->size=0;
}
void circular_buf_put(circular_buf *cbuf, void *data)
{
cbuf->data[cbuf->head] = data;
cbuf->head++;
cbuf->size++;
}
%operator to wrap-around.cbuf_handle_t(or whatevercircular_buf_tthat I would assume it's a pointer to). Please provide enough information to be able to see the problem, and some details about what is specificially giving you that error..objectSize.