mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +00:00
[num-limits] add kBitsPerByte, BitSizeOf(), and BytesForBitSize() (#9618)
This commit removes the use of `CHAR_BIT` in the code and instead defines a constant `kBitsPerByte` for this in `numeric_limits.hpp`. `CHAR_BIT` is generally defined as `8` but there are some platforms were this may not be the case. The way we use `CHAR_BIT` is to determine number of bits in a byte, so introducing our own constant `kBitsPerByte` helps improve code readability and safety. This commit also adds `BitSizeOf()` macro which is similar to `sizeof()` but returns the number of bits of a given type or variable. Macro `BytesForBitSize()` is also added which returns the number of bytes needed to represent a given bit size. This replaces the `BitVectorBytes()` macro previously defined in `encoding.hpp`.
This commit is contained in:
committed by
GitHub
parent
7936f8bcf9
commit
ce9edaf8b5
@@ -210,7 +210,7 @@ void Notifier::LogEvents(Events aEvents) const
|
||||
bool didLog = false;
|
||||
String<kFlagsStringBufferSize> string;
|
||||
|
||||
for (uint8_t bit = 0; bit < sizeof(Events::Flags) * CHAR_BIT; bit++)
|
||||
for (uint8_t bit = 0; bit < BitSizeOf(Events::Flags); bit++)
|
||||
{
|
||||
VerifyOrExit(flags != 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user