As you've found out, you can't automatically tell the size of an unknown piece of data. You'll need either a fixed element type (void*
would be a good generic choice), or have the user pass in the size of each element:
CircularBuffer *cbInit(uint16 size, int elementSize)
{
...
buffer->elementSize = elementSize;
buffer->elements = calloc(size, elementSize);
}