Is int in C Always 32-bit?

后端 未结 8 2014
故里飘歌
故里飘歌 2020-12-05 05:17

This is related to following question,

How to Declare a 32-bit Integer in C

Several people mentioned int is always 32-bit on most platforms. I am curious if

8条回答
  •  爱一瞬间的悲伤
    2020-12-05 05:42

    As several people have stated, there are no guarantees that an 'int' will be 32 bits, if you want to use variables of a specific size, particularly when writing code that involves bit manipulations, you should use the 'Standard Integer Types' mandated by the c99 specification.

    int8_t
    uint8_t
    int32_t
    uint32_t
    

    etc...

    they are generally of the form [u]intN_t, where the 'u' specifies that you want an unsigned quantity, and N is the number of bits

    the correct typedefs for these should be available in stdint.h on whichever platform you are compiling for, using these allows you to write nice, portable code :-)

提交回复
热议问题