c++ - Is size of smallest unit of data written to file on file stream in binary mode always 8 bits? -


as mentioned above,
1-) size of smallest unit of data written file on file stream in binary mode 8 bits? if writes file whatever character passed function put(), can 8 bits?

2-) if add integer variable of char type, position in character set of variable change many integer added, regardless of how bits of variable of char type represented in memory whichever platform/machine tried on? , if exceed limit of value variable can take in system has signed or unsigned char representation of char type? return end begining when adding , reverse extracting?

3-) want know whether there portable way storage data in file binary mode , how common file formats manipulated reading , writing without problems.
thanks.

1) c++ standard pretty clear "byte" (or char) not 8 bits, 1 thing. although machines 9- or 12-bit char types not common, if want extreme portability need take account in way (e.g. specify "our implementation expects char 8 bits - can of course checked during compilation or runtime, e.g:

#if (char_bits != 8)
#error implementation requires char_bits == 8.
#endif

or

if (char_bits != 8) {     cerr << "sorry, can't run on platform, char_bits not 8\n";     exit(2); } 

2) adding int value char value convert int - if convert char, should consistent, yes. although behaviour technically "undefined" overflows between positive , negative values, can cause strange things (e.g. traps overflows) on machines.

3) long it's defined , documents, binary format can made work in portable scenarion. see "jpg", "png" , degree "bmp" examples binary data "quite portable". i'm not sure how works display jpg on dec-10 system 36-bit machine word tho'.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -