uint24_t and uint48_t in MinGW

后端 未结 1 1927
说谎
说谎 2021-01-05 10:06

I\'m looking for uint24_t and uint48_t types in GCC and MinGW. I know neither are standardized, but I\'ve come across references to them online, and I\'m trying to figure ou

相关标签:
1条回答
  • 2021-01-05 11:09

    The standard uintXX_t types are provided in stdint.h (C, C++98) or cstdint (C++11).

    On the 8-bit data, 24-bit address AVR architecture, GCC provides a built-in 24-bit integer, but it is not portable. See http://gcc.gnu.org/wiki/avr-gcc for some more info about it.

    There is no standard 24-bit or 48-bit integer types provided by GCC or MinGW in a platform independent way, but one simple way to get a portable 24-bit number on just about any platform is to use a bitfield:

    struct bitfield24 {
      uint32_t value : 24;
    };
    
    bitfield24 a;
    a.value = 0xffffff;
    a.value += 1;
    assert(a == 0);
    

    The same can be done for 48-bits, using a uint64_t as a base.

    0 讨论(0)
提交回复
热议问题