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
333
votes
6 answers

How to print a int64_t type in C

C99 standard has integer types with bytes size like int64_t. I am using the following code: #include #include int64_t my_int = 999999999999999999; printf("This is my_int: %I64d\n", my_int); and I get this compiler…
rtacconi
  • 12,528
  • 19
  • 64
  • 83
103
votes
4 answers

Why does everybody typedef over standard C types?

If you want to use Qt, you have to embrace quint8, quint16 and so forth. If you want to use GLib, you have to welcome guint8, guint16 and so forth. On Linux there are u32, s16 and so forth. uC/OS defines SINT32, UINT16 and so forth. And if you have…
Amomum
  • 5,447
  • 5
  • 27
  • 54
101
votes
3 answers

vs

What is the difference between stdint.h and cstdint? Both of them are available in MSVC (Visual Studio 2010) and gcc-4.5.1. Also both define the intX_t/uintX_t types (where X is the size in bytes of the type). If the rationale in both headers is…
PaperBirdMaster
  • 11,602
  • 9
  • 41
  • 84
78
votes
2 answers

difference between stdint.h and inttypes.h

What is the difference between stdint.h and inttypes.h? If none of them is used, uint64_t is not recognized but with either of them it is a defined type.
mahmood
  • 19,156
  • 36
  • 118
  • 190
57
votes
4 answers

Why is the maximum size of an array "too large"?

I'm under the same impression as this answer, that size_t is always guaranteed by the standard to be large enough to hold the largest possible type of a given system. However, this code fails to compile on gcc/Mingw: #include #include…
Lundin
  • 155,020
  • 33
  • 213
  • 341
56
votes
2 answers

Where is ptrdiff_t defined in C?

Where is ptrdiff_t defined in C?
Matt Joiner
  • 100,604
  • 94
  • 332
  • 495
51
votes
4 answers

Reasons to use (or not) stdint

I already know that stdint is used to when you need specific variable sizes for portability between platforms. I don't really have such an issue for now, but what are the cons and pros of using it besides the already shown fact above? Looking for…
Sassa
  • 1,133
  • 1
  • 9
  • 22
26
votes
2 answers

How to check if fixed width integers are defined

In C++, fixed width integers are defined as optional, but I can't seems to find the recommended way to check if they are actually defined. What would be a portable way to check if fixed width integers are available?
Rick de Water
  • 2,016
  • 1
  • 13
  • 29
21
votes
2 answers

uint32_t vs uint_fast32_t vs uint_least32_t

I saw different types of definition of an integer in stdint.h. I'll take unsigned 32-bit integer as an example. uint32_t means clearly an unsigned integer of 32 bits. That's the one I always use. uint_fast32_t and uint_least32_t : What's the…
Gabriel L.
  • 3,740
  • 3
  • 23
  • 33
20
votes
4 answers

Define 16 bit integer in C

I need to declare an integer in the size of 16 bit, in C. I know that short and int sizes are machine dependent. I tried to use "stdint.h", but it seems that they simply do typedef short int16_t So my question is: Am I missing something and short…
sara
  • 3,590
  • 8
  • 36
  • 68
19
votes
4 answers

What is this mysterious macro plus sign in stdint.h?

Please see my code: #include int main(int argc, char *argv[]) { unsigned char s = 0xffU; char ch = 0xff; int val = 78; ((int8_t) + (78)); /*what does this mean*/ INT8_C(val); /*equivalent to above*/ signed char + 78; /*not…
Tracy
  • 1,919
  • 2
  • 22
  • 33
18
votes
3 answers

Which C++ standard header defines SIZE_MAX?

I'm working on an existing C++ codebase that happens to use SIZE_MAX in a couple of places. I did some refactoring and now SIZE_MAX is not defined in one of the modules. This problem appeared when Travis-CI attempted to build the project on Linux.…
Greg Hewgill
  • 828,234
  • 170
  • 1,097
  • 1,237
18
votes
5 answers

What is the header file for the uintptr_t type in modern C++?

I found that in C99 you should #include and that seems to work with my C++03 gcc compiler too, but is that the right header for modern C++, is it portable?
WilliamKF
  • 36,283
  • 61
  • 170
  • 271
13
votes
9 answers

Fastest integer type for common architectures

The stdint.h header lacks an int_fastest_t and uint_fastest_t to correspond with the {,u}int_fastX_t types. For instances where the width of the integer type does not matter, how does one pick the integer type that allows processing the greatest…
Matt Joiner
  • 100,604
  • 94
  • 332
  • 495
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
  • 35,407
  • 69
  • 202
  • 359
1
2 3 4 5 6 7