dhess / c-ringbuf

A ring buffer implemented in C
Other
418 stars 143 forks source link

conflicting declaration 'typedef struct ringbuf_t * ringbuf_t:; #21

Open zcattacz opened 2 years ago

zcattacz commented 2 years ago

Issue description

conflicting declaration 'typedef struct ringbuf_t * ringbuf_t;

32 typedef struct ringbuf_t *ringbuf_t
                                                  ^~~~~~
note: previous declaration as 'struct ringbuf_t' 

32 typedef struct ringbuf_t *ringbuf_t
                                ^~~~~~~

Steps to reproduce

Technical details

Hi, thanks for this elegant lib. Just trying to use this in an ESP8266 arduino project. The above definition is preventing compilation. It seems that it does like types to use the same name as the struct it is pointing to, I tried to change the type name, things seems to start to work, but it's really messy. Could you shed some light on how to fix this? Not sure if this is related, I can see -std=gnu++17 flag in detailed compile log.

Regards

dhess commented 2 years ago

Hi, what C compiler are you using? Also, if you could put the full compile log somewhere I can see it (e.g., gist.github.com), that would be helpful.

zcattacz commented 2 years ago

Hi, sorry, this is not a C project issue. I just noticed, the arduino project is a c++ project 😣. I have adapt the code to make it work.

For now I renamed the new type to ringbuf_p ...
I didn't find any explicit information on whether deftype as same name like above is possible or not in cpp. Would appreciate some guidance.

Thank you for your attention.

dhess commented 2 years ago

My C and C++ are rusty, but I can't think of any reason why the code in this project wouldn't be valid C++. I will see if I can find some time this weekend to build it with g++ or clang in C++ mode.

dhess commented 2 years ago

Indeed, C++ is pickier about typedefs that use the same name as an existing type, and also wants a few additional typecasts.

Try this branch:

https://github.com/dhess/c-ringbuf/tree/dhess/c++-fixes

The tests will need more work to make them C++-compliant, but ringbuf.[ch] should be fine now.

elliotwoods commented 11 months ago

Thanks for the library.

Agreed that it would be good to avoid this pattern of not having the struct in the header, and instead having a reciprocal typedef (i'm not sure what this is designed to do exactly also).

I'm including the lib in an extern "C" { so it should be C compatible. Compiler is gcc for STM32.