Aref Aref - 1 month ago 7
C Question

Ubuntu does not provide Clang's stdint which contains uint24_t type

I need to have a 3 byte unsigned integer type. When I look into clang's include path /usr/include/clang/3.5/include the stdint provides a uint24_t data type. But when I want to use it, clang compiler raise an error (error: unknown type name 'uint24_t';)!

#include "stdint.h"
int main()
uint24_t a = 12;
return 0;

Would you please help on how to compile and utilize 24 bit integers in clang?


You could always just mask a larger integer type with the right bit pattern to 24 bits if you need only 24 bits, something like this

int main(int argv, char** argc) {
    uint32_t i = 42 & 0xFFFFFF;

    return 0;

or you could use the C union type with 24 bits you can only have 24 bits.