I am writing a c application for decoding binary files and I need to be sure about the sizes of my chunks. Reading the documentation I understood that only the minimum size is stated while the maximum depends on the compiler or/and architecture…
so could I do something like : ***PSEUDOCODE
unsigned char byte;
if((byte = ~0) > 0xff){
typedef (unsigned char & 0xff) byte; /* I know.. ;P */
}else{
typedef unsigned char byte;
}
should I just apply the bit mask every time I use unsigned char to be sure or is there another way to hard code a size to a type that I don’t know off?
ps: The reason this is important for me is because I going to be doing allot of shifting..
Thank you 😉
Use the types
intN_tanduintN_tfrom stdint.h added in C99 (common values forNare 8, 16, 32, 64). They’re guaranteed to have fixed size.