Closed rickAllDev closed 7 years ago
Since the type of object being stored is not known by the library, you will have to cast the pointer to whatever type you are storing as noted in the documentation:
void *peek(RingBuf *self, unsigned int num);
... Cast the result of this call into a pointer of whatever type you are storing in the buffer....
In your particular case, this would be:
RingBuf *sensor1 = RingBuf_new(sizeof(unsigned int), HISTORICAL_ARRAY_SIZE);
int *data_ptr;
data_ptr = (int*)sensor1->peek(sensor1, i);
This is due to a limitation of C being able to work with generic types, if you would like to avoid having to do this, you can use the C++ version that uses templates:
Thanks for the rapid response on this issue. I did tried to cast because I know you had put that in the documentation but I wrote it as (*int) by mistake. Do you know why it compiles for the Uno without the cast?
No worries, glad you figured it out. The reason why it probably worked is the compiler flags for the uno probably allowed an implicit cast from a void to a int with just a warning, whereas the flags for the esp8266 throw an error.
I've been playing with the RingBuf library and had it working nicely on an Uno. I then compiled it for the ESP8266 and got this error: 'invalid conversion from 'void' to 'int' [-fpermissive]'
I think these would be the pertinent lines... RingBuf sensor1 = RingBuf_new(sizeof(unsigned int), HISTORICAL_ARRAY_SIZE); int data_ptr; data_ptr = sensor1->peek(sensor1, i); ////// this is where it errors out
I've tried versions 1,2 and 3 all with the same results