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
12
votes
1 answer

Why Microsoft Visual Studio cannot find ?

Possible Duplicate: Visual Studio support for new C / C++ standards? See the text below from wiki: The C99 standard includes definitions of several new integer types to enhance the portability of programs[2]. The already available basic integer…
Narek
  • 38,779
  • 79
  • 233
  • 389
10
votes
3 answers

Why do implementations of "stdint.h" disagree on the definition of UINT8_C?

The UINT8_C macro is defined in "stdint.h", with the following specification: The macro UINTN_C(value) shall expand to an integer constant expression corresponding to the type uint_leastN_t. In the wild, however, implementations differ: #define…
Clément
  • 12,299
  • 15
  • 75
  • 115
9
votes
3 answers

uint8_t not rollover to 0 after reaching 255 not working properly

I am new to the C-Headers - stdint.h and inttypes.h. I was trying out some code to get an inkling of how uint8_t works. But, it seems to have encountered a problem. I have declared 4 uint8_t integers with the boundary values 0, 255, 256, -1…
TejasKhajanchee
  • 103
  • 2
  • 8
9
votes
1 answer

Why do stdint.h can be found but cstdint not?

I'm be suprised with that include stdint.h works but include cstdint not. $ aCC sizeof.cpp "sizeof.cpp", line 5: error #2005-D: could not open source file "cstdint" #include ^ 1 error detected in the compilation of…
van
  • 213
  • 1
  • 3
  • 10
8
votes
1 answer

Why in C language for every signed int type must there be a corresponding unsigned int type?

I was reading C in a Nutshell and found this: "If an optional signed type (without the prefix u) is defined, then the corresponding unsigned type (with the initial u) is required, and vice versa." The paragraph is about The integer types with…
eddybudge
  • 165
  • 1
  • 8
8
votes
3 answers

Compile time checking existence of stdint.h

I'm working with legacy embedded C code which defines the types uint8_t, uint16_t and uint32_t in a header file using the typedef keyword. For discussion, let us say the file typedefs.h contains these definitions. In my new C source module, I…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
8
votes
1 answer

VC6: fatal error C1083: Cannot open include file: 'stdint.h'

When compiling in VC6 I am receiving the error: (fatal error C1083: Cannot open include file: 'stdint.h': No such file or directory) Can anyone explain why I am receiving this error?
user2831683
  • 967
  • 1
  • 10
  • 21
7
votes
3 answers

Casting uint32_t to int32_t and comparing them afterwards

I'm having trouble understanding how does comparing two ints, where one is unsigned int32 and the other one signed int32 work. Let's consider this simple program: #include int main() { uint32_t a1 = UINT32_MAX; int32_t b1 =…
MLapaj
  • 371
  • 3
  • 11
7
votes
2 answers

what's the equivalent of atoi or strtoul for uint32_t and other stdint types?

i'm looking for the standard functions to convert a string to an stdint.h integer, like int i = atoi("123"); unsigned long ul = strtoul("123", NULL, 10); uint32_t n = mysteryfunction("123"); // <-- ???
6
votes
2 answers

Including C standard headers in CUDA NVRTC code

I'm writing a CUDA kernel that is compiled at runtime using NVRTC (CUDA version 9.2 with NVRTC version 7.5), which needs the stdint.h header, in order to have the int32_t etc. types. If I write the kernel source code without the include, it works…
tmlen
  • 8,533
  • 5
  • 31
  • 84
6
votes
3 answers

How should the [u]int_fastN_t types be defined for x86_64, with or without the x32 ABI?

The x32 ABI specifies, among other things, 32-bit pointers for code generated for the x86_64 architecture. It combines the advantages of the x86_64 architecture (including 64-bit CPU registers) with the reduced overhead of 32-bit pointers. The…
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
5
votes
3 answers

Portable reinterpretation of uint8_t as int8_t and forcing two's complement

I am trying to reinterpret a uint8_t as an int8_t (and back again) in a way that is portable. I'm as I am receiving over a serial channel that I store in a buffer of uint8_t, but once I know what kind of packet it is, I need to interpret some of the…
Chris
  • 51
  • 3
5
votes
1 answer

C: Is there something wrong with declaring byte arrays as uint8_t?

I'm working on a small networking application that uses byte arrays. Traditionally these would be declared with something like char buf[] = .... This seems to be how it is (still?) done in most tutorials, yet it has the problem that it may obscure…
gmolau
  • 2,815
  • 1
  • 22
  • 45
5
votes
2 answers

Printf with typedef integers, especially 64bit

Consider this code: typedef int64_t Blkno; #define BLKNO_FMT "%lld" printf(BLKNO_FMT, (Blkno)some_blkno); This works well and fine on x86. On x64, int64_t is actually a long, rather than a long long, and while long and long long are the same size…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
5
votes
4 answers

C: uint16_t subtraction behavior in gcc

I'm trying to subtract two unsigned ints and compare the result to a signed int (or a literal). When using unsigned int types the behavior is as expected. When using uint16_t (from stdint.h) types the behavior is not what I would expect. The…
Avi
  • 53
  • 1
  • 3