How does clang uint24_t work? Can I use it outside of clang / LLVM?

As a GCC user, I just noticed that clang supports the uint24_t type ( stdint.h anyway).

How it works? I mean, is it supported exclusively within the country, as a language extension, or is it implemented as a C ++ class, with some abstraction of more than 3 bytes or a 16-bit value and another 8-bit value? And - how much is it possible to "pull out" such an implementation and use it yourself, using GCC?

Note:

  • I want to have the uint24_t class in modern C ++ (or uint_t<N> more generally); my alternative is folding my own.
  • You can s/uint/int/g; if you want, in this matter.
+6
source share
1 answer

This is not portable or standard. It exists only for AVR (which has 24-bit addresses), and GCC has it for this architecture too (since GCC v4.7).

If the architecture does not support its own 24-bit integer, then it will not be determined.

If you look at the header file in Clang stdint.h , you will see that 24-bit integer typedefs are conditionally included only when the internal character __INT24_TYPE__ :

 #ifdef __INT24_TYPE__ typedef __INT24_TYPE__ int24_t; typedef __UINT24_TYPE__ uint24_t; typedef int24_t int_least24_t; typedef uint24_t uint_least24_t; typedef int24_t int_fast24_t; typedef uint24_t uint_fast24_t; # define __int_least16_t int24_t # define __uint_least16_t uint24_t # define __int_least8_t int24_t # define __uint_least8_t uint24_t #endif /* __INT24_TYPE__ */ 
+3
source

Source: https://habr.com/ru/post/1013721/


All Articles