View previous topic :: View next topic |
Author |
Message |
bryant@balancebitsconsult
Joined: 21 Nov 2023 Posts: 38
|
circular buffer / ring buffer |
Posted: Wed Dec 06, 2023 1:20 pm |
|
|
There are lots of reasons to have a ring buffer, and doing it wrong can introduce bugs.
I caught myself writing a circular (ring) buffer from scratch and built ( tail == head accidentally without detecting if the buffer was full or not). So I went looking for decent embedded implementation of a ring buffer that I could throw a struct (typedef'd) with a length to push/pop from.
I found one, and believe it's appropriate. There are some advanced preprocessor directives in this code, but nothing too crazy.
https://github.com/beadon/circbuf_demo
I needed to make some edits to the utility since it requires the use of compound literals. Adjusting this, and then moving things around proved it is working as expected.
In the future --
How can I get debug messages from the preprocessor ? (is this a thing ? ) |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Dec 08, 2023 3:04 am |
|
|
The compiler does not have a preprocessor.
I've often wished you could (for example), see the output from after
macro expansion. |
|
|
bryant@balancebitsconsult
Joined: 21 Nov 2023 Posts: 38
|
|
Posted: Fri Dec 08, 2023 10:56 am |
|
|
Ttelmah wrote: | The compiler does not have a preprocessor.
I've often wished you could (for example), see the output from after
macro expansion. |
I see. I also am interested in seeing it for the same reasons. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Mon Dec 11, 2023 8:37 am |
|
|
as a slight comment, I would recommend avoiding the use of _ and __ as the lead in to your names. It's technically reserved by the C standard (see section 7.1.3 I think). Not a huge deal, but if you want your code universally usable across as many compilers as possible, then I would avoid it. |
|
|
|