On 2010-12-16, raffamaiden <firstname.lastname@example.org> wrote:
> Hi all. I'm writing a program wich will write some variables to an
> output file. I do something like
> int a =5;
> fwrite(&a, sizeof(int), 1, my_file_ptr);
> This will write an int to the file pointed by my_file_ptr. But i know
> that the c standard does not specify the exact size in bytes for its
> primitive type, as far as i know it only specifies that and int is an
> integer type that rapresents a number with a sign, but different
> implementations\operating systems can have different size for an int.
> So this mean that my program will write a 32 bit integer with one
> implementation and a 16 bit with another implementation. This would
> also mean that the file generated by the program that is running in
> one implementation will not be readable in another implementation,
> unless the program knows also in which implementation the instance
> that generated the file was running.
> That is right? I do not want such a behavior. How can i solve this?
read and write the file one byte at a time.
or use textual representations
⚂⚃ 100% natural
comp.lang.c.moderated - moderation address: email@example.com
-- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.