Questions tagged [stdint]

stdint.h is a header file in the C standard library to allow programmers to write more portable code.

stdint.h introduced in the C99 standard library section 7.18 and it provides a set of typedefs that specify exact-width integer types, together with the defined minimum and maximum allowable values for each type, using macros.

This header is particularly useful for embedded programming which often involves considerable manipulation of hardware specific I/O registers requiring integer data of fixed widths, specific locations and exact alignments.

Read more

118 questions
4
votes
3 answers

Why does stdatomic.h contain atomic_uint_least16_t and atomic_uint_fast16_t but not atomic_uint16_t?

stdatomic.h appears to contain atomic_uint_least16_t and atomic_uint_fast16_t, which are _Atomic versions of the stdint.h types uint_least16_t and uint_fast16_t, but it does not contain atomic_uint16_t. Why? For some background information from the…
Jason S
  • 184,598
  • 164
  • 608
  • 970
4
votes
1 answer

Why is assignment with possible loss of data NOT producing compiler warning

I'm using MS Visual Studio 2017 and (as expected) I get the compiler warning: Warning C4244 '=': conversion from 'unsigned long' to 'unsigned short', possible loss of data on this C++ code: unsigned long test32{70000}; unsigned short…
NKatUT
  • 429
  • 3
  • 10
4
votes
3 answers

Should I use the stdint.h integer types on 32/64 bit machines?

One thing that bugs me about the regular c integer declarations is that their names are strange, "long long" being the worst. I am only building for 32 and 64 bit machines so I do not necessarily need the portability that the library offers, however…
YeOldeBitwise
  • 133
  • 1
  • 2
  • 8
4
votes
0 answers

Tool for refactoring types in C code

I'm looking for a tool which can refactor types (!) in C code. I have a complex and relatively big codebase where we decided to switch from built-in integral types to types with explicit width. Like changing every instances of "unsigned int" to…
Ben Hirschberg
  • 1,410
  • 1
  • 12
  • 17
4
votes
2 answers

Difference between C-Types int32_t int_least32_t etc

I have ever read that int32_t is exact 32 bits long and int_least32_t only at least 32 bits, but they have both the same typedefs in my stdint.h: typedef int int_least32_t; and typedef int int32_t; So where is the difference? They exactly the…
Sebi2020
  • 1,966
  • 1
  • 23
  • 40
3
votes
1 answer

Is it necessary to include to guarantee portability of C99 new types?

From my understanding C99 new types such as uint32_t, uint_fast64_t, uintmax_t etc. are defined in . However, I noticed they're also defined in stdlib.h, and from gnu.org I found out that it is one of many headers checked, but in other…
MDXZ
  • 160
  • 12
3
votes
1 answer

How do I find the width of a uint_fast32_t

I'd like to be able to portably fprintf() a uint_fast32_t as defined in stdint.h with all leading zeroes. For instance if my platform defined uint_fast32_t as a 64-bit unsigned integer, I would want to fprintf() with a format specifier like %016lX,…
Willis Hershey
  • 1,520
  • 4
  • 22
3
votes
1 answer

Why is size_t in stddef and not stdint?

I'm just wondering why things like uintptr_t are in stdint.h, but other types like size_t are in stddef.h? Is there logic behind these headers?
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
3
votes
1 answer

Standard byte sizes for variables in C?

So, I was writing an implementation of ye olde SHA1 algorithm in C (I know it's insecure, it's for the Matasano problems), and for some of the variables it's pretty crucial that they're exactly 32 bits long. Having read that unsigned long int is 32…
gmoss
  • 1,019
  • 5
  • 17
3
votes
1 answer

using stdint with swig and numpy.i

I'm developing a module for using c inline in Python code based on swig. For that I would like to make numpy arrays accessible in C. Until now I used C types like unsigned short but I would like to use types like uint16_t from stdint.h to be save…
jochen
  • 413
  • 2
  • 10
3
votes
3 answers

Is there a way to fix format specifiers warnings for stdint types?

The problem is that on one platform (windows, mvsc2015) uint64_t is defined as unsigned long long and on another (ubuntu, clang) it's unsigned long and there is the code which looks like sprintf(buffer, "%#llx", u64key);
Dan M.
  • 3,818
  • 1
  • 23
  • 41
3
votes
3 answers

Is there a portable way to know if uintptr_t is defined in stdint.h?

Preamble: I want to convert a pointer to an integer type, e.g. to check alignment. uintptr_t seems to be the correct type, but it is guaranteed only in C, not in C++ (or C++11) For the following code: #include #ifndef…
Antonio
  • 19,451
  • 13
  • 99
  • 197
3
votes
1 answer

Object storage for exact-width integer types

Are implementations allowed to use more than N bits as object storage for intN_t and uintN_t types, provided the values stored in them fit the required range? For example, consider a CPU which uses 9-bit bytes. An implementation written for this CPU…
Drew McGowen
  • 11,471
  • 1
  • 31
  • 57
3
votes
2 answers

Notepad++ and stdint.h types

Notepad++ C and C++ builtin languages, do not recognize stdint types (uint8_t etc) and as such these types do not get colored. Is there a way to extract the builtin language, so that the stdint types are inserted, whithout having to create a new…
George P.
  • 140
  • 1
  • 1
  • 7
3
votes
1 answer

equivalent of double in stdint.h?

I am trying to figure out my way through c89 and now I ma stuck with this problem. Does stdint.h have any equivalent for double data type? If yes how do we print it?
Aman Deep Gautam
  • 8,091
  • 21
  • 74
  • 130