类似 uint32、 int32、 uint64、 int64的类型是否在任何 stdlib 头中定义?

我经常看到源代码使用像 uint32,uint64这样的类型,我想知道它们是否应该由程序员在应用程序代码中定义,或者它们是否在标准的 lib 头中定义。

在我的应用程序源代码中使用这些类型的最佳方法是什么?

244268 次浏览

Those integer types are all defined in stdint.h

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.

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

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".