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
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,947
  • 7
  • 32
  • 55
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
  • 137
  • 2
  • 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
  • 62,085
  • 98
  • 303
  • 499
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
  • 52,985
  • 32
  • 103
  • 124
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
  • 15,383
  • 51
  • 135
  • 216
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,582
  • 3
  • 15
  • 33
0
votes
3 answers

Why is a cast of uintptr_t used here?

Here it is, in the context of pthread.h and stdint.h: struct arguments { uint32_t threads; uint32_t size; }; void *run_v1(void *arg) { uint32_t thread = (uintptr_t) arg; for (uint32_t j = 0; j < arguments.size; ++j) { size_t…
user129393192
  • 797
  • 1
  • 8
0
votes
3 answers

What does *((uint32_t)foo) return

Looking at the code: #include #include int main() { char foo[512]={}; printf("%d", *((uint32_t*)foo)); return 0; } I'm having hard time understanding what *((uint32_t*)foo)) does, Using different values in array…
Broman3100
  • 19
  • 5
0
votes
0 answers

Why my uint16_t in a Struct uses 4 bytes of memory with a fresh install of GCC in VSCode on Windows?

I just installed VSCODE, MSYS2 and GCC on my W11 PC. This is a by default install. In order to play with .bmp file I have a small piece of code using a struct for the header. Start of the struct definition is : struct bmp_header_st{ uint16_t…
AIM65
  • 1
0
votes
2 answers

How using stdint.h has advantage of portability?

I read that stdint.h is used for portability, but I'm confused. If I wrote a program on a 32-bit system, uint32_t (unsigned int) is 4-bytes. But when this program is run on 16-bit system, int is 2bytes and uint32_t (unsigned int) is 2bytes. I think…
porpomas
  • 41
  • 4
0
votes
0 answers

Are there any platforms that define fixed-width types from stdint.h with bits other than 8, 16, 32 or 64?

The header file usually provides typedefs and macro constants for integers of 8, 16, 32 and 64 bit width. The standard also allows any N-bit type to be specified by using identifiers of the form uintN_t, etc, although I personally have…
saxbophone
  • 779
  • 1
  • 6
  • 22
0
votes
2 answers

How does type conversion and integer promotion work for stdint.h?

In C, I understand type conversions, integer promotion, casting, etc. for standard types, but how do the stdint.h types factor into this? For type rankings, the rules state: No two signed integer types shall have the same rank, even if they have…
user1801359
  • 422
  • 1
  • 4
  • 14
0
votes
1 answer

Format specifier in causes warning in cross-platform compatibility

I am using library () for compatibility across platforms in usigned types. When compiling on my MacOSX with -Wall options no warnings arise, while on Ubuntu 20.04 I get mvmpi.c: In function ‘main’: mvmpi.c:33:9: warning:…
opisthofulax
  • 517
  • 8
  • 25
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…
kamelfanger83
  • 97
  • 1
  • 7