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
1
vote
0 answers

Difference between intptr_t and uintptr_t

Why do we need intptr_t and uintptr_t for storing pointer addresses, even though pointers are positive values?
Killbill
  • 37
  • 1
1
vote
4 answers

Can I use int8_t instead of char?

I made a short code like below. #include #include #include #include int32_t main(int32_t argc, int8_t *argv[]) { int32_t i; if (argc < 1) { printf("Error\n"); } for (i = 0 ; i <…
Cprogrammer
  • 153
  • 9
1
vote
2 answers

Is this a bug in glibc printf?

Using stdint.h from glibc (gcc SUSE Linux version 9.2.1, Intel Core I7 processor) I came across a most strange behaviour when printing INT32_MIN directly: #include #include void main(void) { printf("%d\n", INT16_MIN); …
Arc
  • 412
  • 2
  • 16
1
vote
1 answer

How does casting between Cs default int type and 's intXX_t types work?

I'm working in a code skeleton that has a lot of preexisting code using the regular old int type in C. However, the code I need to write requires that I use a fixed length int32_t. However, I need to be able to take input from the regular code in…
LSR
  • 35
  • 3
1
vote
1 answer

Legal to initialize uint8_t array with string literal?

Is it OK to initialize a uint8_t array from a string literal? Does it work as expected or does it mangle some bytes due to signed-unsigned conversion? (I want it to just stuff the literal's bits in there unchanged.) GCC doesn't complain with -Wall…
jdm
  • 9,470
  • 12
  • 58
  • 110
1
vote
1 answer

stdint.h include_next'd from stdint.h not found

I have been putting together a m68k cross compile "environment/toolchain" of sorts for some upcoming projects I have planned, and I'm having an issue when using it on macOS (my native environment) specifically. If I follow my own instructions to…
Tom S
  • 11
  • 1
  • 4
1
vote
1 answer

uint32_t seems to be unknown in the CMSIS Math files?

I am getting the error: CMSIS/DSP/Include/arm_math.h:3943:3: error: unknown type name 'uint32_t'; did you mean 'wint_t'? I could add stdint.h to the arm_math.h but I assume I did something wrong in the first place. Surely the CMSIS developer would…
Drimer
  • 93
  • 2
  • 14
1
vote
3 answers

How do you determine if your machine supports a standard integer datatype in C?

I'm somewhat familiar with the concept of stdint.h in C. By explicitly stating the size of the integer, the header file will replace the #define integer with the appropriate integer on that machine. For example, if my machine has 16 bit unsigned…
Izzo
  • 4,461
  • 13
  • 45
  • 82
1
vote
1 answer

Why does type int work with sscanf but int16_t doesn't?

I'm trying to assign values from user input stream to variables M and N. I can get my code to work if I specify M and N of type int. However, when i specify them as int16_t using the stdint.h it will read the first value in but the last value it…
bAsH
  • 25
  • 4
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
  • 13,248
  • 8
  • 43
  • 78
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
  • 6,061
  • 5
  • 25
  • 49
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
  • 8,061
  • 12
  • 67
  • 123
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
  • 4,053
  • 25
  • 38