wizard97 / ArduinoRingBuffer

A Simple Interrupt Safe Ring (Circular) Buffer Queuing Library for Programming with Arduino's and other Embedded platforms
MIT License
110 stars 23 forks source link

Issues compiling for ESP8266 with Arduino IDE #5

Closed rickAllDev closed 7 years ago

rickAllDev commented 7 years ago

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

wizard97 commented 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:

rickAllDev commented 7 years ago

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?

wizard97 commented 7 years ago

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.