I would like char, short and int types to be 1, 2 and 4 bytes width. I have included a stdint.h header into my sources. Does this guarantee that int8_t, int16_t and int32_t integer types will be of widths specified? What is the best way to achieve this?
相关问题
- Multiple sockets for clients to connect to
- Do the Java Integer and Double objects have unnece
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
If these types exist, they have the correct width and are encoded in two's complement.
Edit: you should be able to check if the types exist with something like
but on all end user architectures (PC etc) these types do usually exist.
You can check: Size of int in C on different architectures
C99's stdint.h does not actually guarantee that these types exist. To quote wikipedia:
However, if they do exist, they will be the correct widths.
stdint.h
some exact-width integer types. These are (from wikipedia):Use them if you want to know what the size is for definite. C99 requires that these types have the sizes specified. All other types are platform dependent.
Other types are guaranteed to be a certain minimum width, as per
limits.h
. But they could equally be bigger than that. It is up to the implementation.The whole purpose of the types defined in
stdint.h
is of them to be of specified width. Soint8_t
will be 8 bits wide,int16_t
- 16 bits wide, etc.