Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.programming Subject: Re: A little puzzle. Date: Thu, 24 Nov 2022 13:23:51 +0000 Organization: A noiseless patient Spider Lines: 21 Message-ID: <878rk0iizc.fsf@bsb.me.uk> References: <875yf8nijb.fsf@bsb.me.uk> <865yf79l66.fsf@linuxsc.com> <87wn7nj9mb.fsf@bsb.me.uk> <86sfi98xnx.fsf@linuxsc.com> <87leo1i5bo.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="66cc716c1d8e20186aec3fe895a20c78"; logging-data="707126"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+V6/VVeXkUmgW/vWSvhQ2JrY4m+ZDb9mM=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cancel-Lock: sha1:mk8Fv30oQFBKRHhPocfygFzOoc4= sha1:mbBVeqi5mP0FrMSisZ0sE21m2QQ= X-BSB-Auth: 1.ee65f1653e74f2de8467.20221124132351GMT.878rk0iizc.fsf@bsb.me.uk Xref: csiph.com comp.programming:15957 David Brown writes: > I use circular buffers a great deal in my coding. For many of my > systems, there are UART communication ports (such as for debugging > output - when you don't have a screen or standard output, a UART does > the job). There is typically a circular buffer which is piped out to > the port via interrupt routines, and when the application code wants > to "print" out a message, it gets pushed into the buffer. Yes, and I've used circular buffers before, but always as queues so there was never a need to know if an index (or pointer) is in the filled or unfilled region. One just had to avoid confusing a full buffer with an empty one. > So the kind of thought needed for Ben's "puzzle" turns up in real > code, and I've seen people get it wrong. What's the modulo solution you had in mind? -- Ben.