Liste des Groupes | Revenir à cl c |
On 2025-03-25, David Brown <david.brown@hesbynett.no> wrote:The minimum size for an "unsigned char" is 8 bits. There are no other standard integer types that are unsigned, have no padding bits, and can be 8 bits in size (except that plain "char" can be identical to "unsigned char"). "uint8_t" is a typedef of an integer type that is exactly 8 bits, with no padding. There can be no C implementation for which "uint8_t" can exist, and for which "unsigned char" is not an appropriate choice. No other standard integer types can possibly be suitable (except perhaps "char").Personally, I think "typedef uint8_t byte;" /is/ ideal - and much betterThe problem is that uint8_t is not endowed with the special
than "typedef unsigned char byte;" would be. I say that as someone who
works in a field with bits and bytes more than ints and doubles.
aliasing rules for accessing objects of other types as arrays
of unsigned char. A type called byte is prone to precipitating
into those uses.
A platform like Arduino could assert that in their toolchain,"uint8_t" is a typedef - not its own integer type. If it is a typedef of "unsigned char" (as it is for the AVR gcc port, used by the Arduino), it inherits the magic aliasing powers of "unsigned char" - typedef names an alias, not a new type.
the type byte does have those properties (and then somehow ensure
that is true, in spite of it being uint8_t, like by patching
the compiler if they have to).
Les messages affichés proviennent d'usenet.