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

103 questions
1
vote
2 answers

stdint.h and C99

I read in the C99 standard that stdint.h is part of the C standard library. Do I read correctly that, if I test for C99 compliance, using: defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) that means stdint.h is supposed to be…
Cyan
  • 11,534
  • 6
  • 33
  • 68
1
vote
1 answer

How to prevent cppcheck (v1.72) warnings for %"PRIi64" (%lld) with a int64_t variable (cpcheck thinks it is a signed int) of stdint.h

For a sequence of typedef int64_t I64; I64 i=5; printf("%"PRIi64",i); cppcheck gives the warning below: warning: %lld in format string (no. 1) requires 'long long' but the argument type is 'signed int'. The makro PRIi64 is resolved by lld,…
1
vote
1 answer

Inconsistency with inttypes.h, fscanf(), fprintf()

I'm having some problems with inttypes, illustrated here by this tiny code sample: #include #include #include void print_byte(uint8_t b) { printf("%d%d%d%d%d%d%d%d\n", !!(b & 128), !!(b & 64), !!(b…
user3618511
  • 105
  • 5
1
vote
1 answer

How to use abs and div with fixed-size integers

In C99 we have fixed-size integer types, defined in stdint.h. In stdlib.h we have the abs and div functions which operate on ints, as well as their long int/long long int counterparts labs, llabs, ldiv, lldiv. Since the size of int/long/long long…
Askaga
  • 5,379
  • 4
  • 20
  • 45
1
vote
1 answer

Detect stdint.h and C++11 on android NDK

I found somewhere that i could detect C++11 using the following line : #if __cplusplus <= 199711L I'm using this to conditionally defined fixed-width types such as int32_t or uchar16_t, etc... The problem is that when using the android NDK,…
Virus721
  • 7,156
  • 8
  • 49
  • 110
1
vote
0 answers

Why does GCC define only __INT8_MAX__ and not __INT8_MIN__?

GCC's predefined macro includes __INT8_MAX__ but not __INT8_MIN__. INT8_MIN is defined in stdint.h with (-__INT8_MAX - 1). Does GCC assume that the system is in two's complement? I think (INT8_MAX +1) is a better way to define INT8_MIN since it'll…
Inbae Jeong
  • 3,823
  • 23
  • 36
1
vote
1 answer

How can I extract blocks of Bytes from a int32_t and store it in a int16_t or int8_t using c?

If I have, for example: int32_t x = 572662306; /* 00100010001000100010001000100010 */ I want to store the the two most significant bytes in an int8_t: 00100010 (base 2) = 34 (base 10) Or the four most significant bytes in an…
1
vote
1 answer

how to build Qt5 with qtwebkit on Windows with MSVC 2008 - leveldb can't find stdint.h

On a Windows 7 x64 box: I installed Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 I downloaded and unzipped Qt5.4.0 source from the "Source packages and Other releases" section of http://www.qt.io/download-open-source/# I built ICU…
David Burson
  • 2,465
  • 5
  • 28
  • 49
1
vote
1 answer

Converting 16-bit integer to 8-bit integer?

I'm implementing C code to copy a 16-bit sign and magnitude integer to an 8-bit sign and magnitude integer. Is that even possible? Could someone please explain how to do this? code snippet: int16_t a = 0x1234; int8_t b, c; How to copy first two…
Rohith Gowda
  • 127
  • 1
  • 2
  • 12
1
vote
3 answers

How to sign extend a 9-bit value when converting from an 8-bit value?

I'm implementing a relative branching function in my simple VM. Basically, I'm given an 8-bit relative value. I then shift this left by 1 bit to make it a 9-bit value. So, for instance, if you were to say "branch +127" this would really mean, 127…
Earlz
  • 57,517
  • 89
  • 275
  • 484
1
vote
1 answer

MISRA C 2004 and c99

Rule 1.1 of the MISRA C 2004 specifies that the spec covers c90 and not c99. I would like to use the stdint and stdbool libraries instead of coding my own. Has anyone made this exception in their MISRA implementation?
JeffV
  • 47,302
  • 31
  • 96
  • 120
1
vote
2 answers

C type declaration intN_t

How does the header stdint.h define u32 to be 32 bits on every machine? Could somebody elaborate on the process that stdint.h does to make this happen? Where can I find my machine's (Windows 7) stdint.h file?
CodeKingPlusPlus
  • 12,865
  • 46
  • 123
  • 204
1
vote
2 answers

Best practice: Use of stdint types in a header file

What's the best way to ensure that stdint.h is included for headers that use the types from that header? The alternatives I can see are: including stdint.h in the header itself (dangerous, is it not?) flagging something to the compiler if it's not…
Chris Browne
  • 1,402
  • 2
  • 13
  • 30
0
votes
0 answers

g++ can‘t find stdint.h Windows

I have a program that uses the header stb_image.h ini which the stdint.h header is included. The program works completely fine when compiling it in my IDE (Clion). It is now finished however and I would like to have an .exe file of it. So I tried…
0
votes
2 answers

Searching elements in an array

I want to search the index of the element in array days[] of uint8_t type which has next-to-next elements of 0x2 and 0x3 using a variable of type uint16_t and print the index value of the element '0x2'. I have assigned 'uint16_t search = 0x23' but I…
Beginner
  • 73
  • 3