Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

c - Are there fixed size integers in GCC?

On the MSVC++ compiler, one can use the __int8, __int16, __int32 and similar types for integers with specific sizes. This is extremely useful for applications which need to work with low-level data structures like custom file formats, hardware control data structures and the like.

Is there a similar equivalent I can use on the GCC compiler?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ISO standard C, starting with the C99 standard, adds the standard header <stdint.h> that defines these:

uint8_t  - unsigned 8 bit
int8_t   - signed 8 bit
uint16_t - unsigned 16 bit
int16_t  - signed 16 bit
uint32_t - unsigned 32 bit
int32_t  - signed 32 bit
uint64_t - unsigned 64 bit
int64_t  - signed 64 bit

I use these types all the time.

These types are defined only if the implementation supports predefined types with the appropriate sizes and characteristics (which most do).

<stdint.h> also defines types with names of the form (u)int_leastN_t (types that have at least the specified width) and (u)int_fastN_t (the "fastest" types that have at least the specified width); these types are mandatory.

If you're using an old implementation that doesn't support <stdint.h>, you can roll your own; one implementation is Doug Gwyn's "q8".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...