Coding style: uint8_t for 256 entries
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Coding style: uint8_t for 256 entries
The bottom line is I made my small table exactly 256 entries to fit neatly in the uint8_t that I was using to iterate it (choosing arbitrary sizes for tables is difficult) so it seems like I should stick to the uint8_t that determined that size. Furthermore, as I was choosing the size of the table around the uint8_t, 255 is in fact the correct size.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: Coding style: uint8_t for 256 entries
You are right for unsigned integers. I didn't know / forgot about this. But is is undefined for signed integers:C99 standard (§6.2.5/9) wrote: A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.
As to why that is, check this link:C99 standard (§3.4.3/1) wrote: An example of undefined behavior is the behavior on integer overflow
http://stackoverflow.com/questions/1819 ... verflow-is
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Coding style: uint8_t for 256 entries
Interesting comments, I hadn't thought of that before. Nevertheless I can find many "obscure" ways of representing unsigned integers, but there truly is only one system that's in common use and while there are multiple ways of representing signed integers that all allow the same range of numbers to be represented and that give similar performance, that is not true for unsigned integers as there is really only one system that *should* be used (ordinary binary).kiznit wrote:You are right for unsigned integers. I didn't know / forgot about this. But is is undefined for signed integers:C99 standard (§6.2.5/9) wrote: A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.
As to why that is, check this link:C99 standard (§3.4.3/1) wrote: An example of undefined behavior is the behavior on integer overflow
http://stackoverflow.com/questions/1819 ... verflow-is
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing