Compare this declaration from your header ...
void init_buffer(buffer *q,uint8_t max_size);
... to this one from your .c file:
void init_buffer(Buffer *q,uint8_t max_size)
C identifiers are case sensitive, so regardless of anything else, it is of immediate concern that those don't match with respect to the spelling of the type of their first parameters.
The typedef declared in the header ...
typedef struct Buffer Buffer;
... supports the latter, but not the former.
Note well that as I said in comments, typedef
and struct
are distinct things. The struct
keyword is used in declaring and referencing structure types. The typedef
keyword is used to declare an alias for a type name. These can be used together, and they can be used separately, but IMO, it is usually better not to use typedef
at all. Example:
circular-buffer.h
#ifndef INC_CIRCULAR_BUFFER_H_
#define INC_CIRCULAR_BUFFER_H_
#include <stdint.h>
struct Buffer;
void init_buffer(struct Buffer *q, uint8_t max_size);
#endif
circular-buffer.c
#include <stdint.h>
#include "circular-buffer.h"
struct Buffer {
uint8_t *values;
uint8_t head, tail, num_entries, size;
};
void init_buffer(struct Buffer *q, uint8_t max_size) {
//Here goes the function body
}
If you insist on using typedef
then best practice would be to choose one spelling / capitalization. It would be most conventional to choose the structure tag for that (and C++ gives you that effect automatically), but in practice, you can choose any type alias you want. Or even multiple.
But note that typedef
can get a little sticky. Historically, it was not allowed to declare the same typedef
multiple times in the same translation unit, even if the definitions were identical. That's relaxed in the current version of the language, but your compatibility with older compilers is improved if you avoid, say, having the same typedef in both the .c file and the header (supposing that the former is going to #include
the latter).
Recommended typedef
usage:
circular-buffer.h
#ifndef INC_CIRCULAR_BUFFER_H_
#define INC_CIRCULAR_BUFFER_H_
#include <stdint.h>
struct Buffer;
typedef struct Buffer Buffer;
void init_buffer(Buffer *q, uint8_t max_size);
#endif
circular-buffer.c
#include <stdint.h>
#include "circular-buffer.h"
struct Buffer {
uint8_t *values;
uint8_t head, tail, num_entries, size;
};
void init_buffer(Buffer *q, uint8_t max_size) {
//Here goes the function body
}