Re: 32 vs. 64 bit binary files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If you don't have some kind of header in the file you can't know this.
 A file is just a bunch of data.  The alternative to writing an
additional header in your file is to guarantee that it is 32 bit or 64
bit.  Since you already have files in 32 bit, you could use int32_t
instead of Long.

If you want to get creative, you could set a negative value in height
to notify you that the format has changed (since I'm assuming that
height is always non-negative?), and then based on that number (which
must still be 32 bits for backward compatibility reasons), you can
divine the format.

  Brian

On Wed, Nov 11, 2009 at 3:22 PM, Brian McGrew <brian@xxxxxxxxxxxxx> wrote:
> So we've run into our first real snag on the conversion road from 32 to 64
> bit.  We write out a binary file full of data and then read it back in using
> fwrite and fread.
>
> My file format is pure binary and it's as follows:
>
> Long height
> Long width
> For (short; height * width)
> Long
> Long
>
> So in the 32 bit world, this works great.  But when trying to read these 32
> bit files into software on the 64 bit systems, I'm running into problems!
>
> There are no delimeters in my file that I can use to determine which arch
> the file was written on.
>
> What I need is some kind of method to determine the arch, possibly based on
> the file???  I don't know???  All I need to know is, from the code level, if
> it's a 32-bit binary file or a 64-bit binary file?
>
> Thanks,
>
> -b
>
>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux