Re: Structure size and binary format
- From: Mark McIntyre <markmcintyre@xxxxxxxxxxx>
- Date: Sat, 31 Dec 2005 00:29:16 +0000
On 30 Dec 2005 16:05:03 -0800, in comp.lang.c , "gamehack"
<gamehack@xxxxxxxxx> wrote:
>Hi all,
>
>I've been wondering when I write a structure like:
>
>struct {
>int a;
>unsigned int b;
>float c;
>} mystruct;
>
>And then I'm using this as a record for a binary file. The problem is
>that the size of the types is different on different
>platforms(win/lin/osx) so if a file was copied on another platform and
>attempted to be read then the first say 16 bytes could be regarded as
>the integer a but it could have been created on system where integer
>was 32 bytes. Is there a portable solution to this?
The simplest is to store the data as text, not binary data. Other
methods might involve using fixed-width data types (if your platforms
support them), or writing custom load/save functions for each platform
which still store in binary but do it element by element and take into
account the differing sizes of types on each platform.
Mark McIntyre
--
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
.
- References:
- Structure size and binary format
- From: gamehack
- Structure size and binary format
- Prev by Date: Re: Input-line reverser
- Next by Date: Re: Input-line reverser
- Previous by thread: Structure size and binary format
- Next by thread: Re: Structure size and binary format
- Index(es):
Relevant Pages
|