Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

gcc

clang

Being a GCC user, I've just noticed clang supports a uint24_t type (it's in their stdint.h anyway).

How does that work? I mean, is it supported purely internally, as a language extension, or is it implemented like a C++ class would, with some abstraction over 3 bytes or a 16-bit value and another 8-bit value? And - how possible is it to 'yank' such an implementation and use it myself, with GCC?

Note:

  • I'm looking to have a uint24_t-like class in modern C++ (or a uint_t<N> more generally); my alternative is rolling my own.
  • You can s/uint/int/g; if you like in this question.
like image 949
einpoklum Avatar asked Jan 03 '17 10:01

einpoklum


Video Answer


1 Answers

This isn't portable or standard. It exists only for AVR (which has 24-bit addresses), and GCC has it for that architecture, too (since GCC v4.7).

If the architecture doesn't support a native 24-bit integer, then it won't be defined.

If you look in Clang's stdint.h header file, you'll see that the 24-bit integer typedefs are conditionally included only when the internal __INT24_TYPE__ symbol is defined:

#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__ */
like image 110
Cody Gray Avatar answered Oct 18 '22 05:10

Cody Gray