Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Consulting on my next project

Status
Not open for further replies.
Thank you NorthGuy :)

Are you sure about having Head always larger than Tail?

At some point, Head will "overflow" and will start counting from 0 again, while Tail is yet to overflow and therefore be larger than Head, right?
 
Thank you NorthGuy :)

Are you sure about having Head always larger than Tail?

At some point, Head will "overflow" and will start counting from 0 again, while Tail is yet to overflow and therefore be larger than Head, right?

If they're 32-bit numbers, they only overflow at 4294967296, but if they do overflow, it doesn't really matter. You simply define Size as unsigned int.

C:
unsigned int Size;
 
Size = Head - Tail;

If Tail is 0xffffff80 and Head overflowed to 0x10, the difference will be calculated correctly as 0x90.
 
Hi again NorthGuy.

Thank you friend :)

If Size is unsigned int.
Lets take the case where there were (2^32 + 100) bytes written, so
Head = 100
And say that
Tail = 4294967196 (which is 2^32 - 100)

e.g. Size should be 200.

Size = Head - Tail = 100 - 4294967196 = -4294967096

Does it really turn out to be 200?
 
Status
Not open for further replies.

Latest threads

Back
Top