I am reading/writing chars to a binary file. The program doing the reading/writing may run on either a 32 or 64 bit machine. Furthermore, the file could be written in a 32-bit environment then read in 64 and vice-versa.
Therefore I need some way of storing chars that guarantees a certain width (the smaller the better). I’m sure there is an accepted/common way to do this, but being a C novice I don’t know it, and also can’t find anything via google..
Does any one know the trick?
On any “normal” modern architecture
chars are always of 8 bits, regardless of 64/32 bit issues. Those arise when you dump directly on a file the binary representation ofintor other types (which can vary in size and byte ordering depending on architecture), but plainchars should be safe.… obviously if you are writing text you should choose some encoding, but that’s a completely different story…