CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

circular buffer / ring buffer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bryant@balancebitsconsult



Joined: 21 Nov 2023
Posts: 22

View user's profile Send private message

circular buffer / ring buffer
PostPosted: Wed Dec 06, 2023 1:20 pm     Reply with quote

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: 19244

View user's profile Send private message

PostPosted: Fri Dec 08, 2023 3:04 am     Reply with quote

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: 22

View user's profile Send private message

PostPosted: Fri Dec 08, 2023 10:56 am     Reply with quote

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: 1319

View user's profile Send private message

PostPosted: Mon Dec 11, 2023 8:37 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group