Are types like uint32, int32, uint64, int64 defined in any stdlib header?

CLibc

C Problem Overview


I often see source code using types like uint32, uint64 and I wonder if they should be defined by the programmer in the application code or if they are defined in a standard lib header.

What's the best way to have these types on my application source code?

C Solutions


Solution 1 - C

The C99 stdint.h defines these:

  • int8_t
  • int16_t
  • int32_t
  • uint8_t
  • uint16_t
  • uint32_t

And, if the architecture supports them:

  • int64_t
  • uint64_t

There are various other integer typedefs in stdint.h as well.

If you're stuck without a C99 environment then you should probably supply your own typedefs and use the C99 ones anyway.

The uint32 and uint64 (i.e. without the _t suffix) are probably application specific.

Solution 2 - C

Those integer types are all defined in stdint.h

Solution 3 - C

If you are using C99 just include stdint.h. BTW, the 64bit types are there iff the processor supports them.

Solution 4 - C

The questioner actually asked about int16 (etc) rather than (ugly) int16_t (etc).

There are no standard headers - nor any in Linux's /usr/include/ folder that define them without the "_t".

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionphilixView Question on Stackoverflow
Solution 1 - Cmu is too shortView Answer on Stackoverflow
Solution 2 - CGWWView Answer on Stackoverflow
Solution 3 - CBiGYaNView Answer on Stackoverflow
Solution 4 - CSteveView Answer on Stackoverflow