Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #57127

Re: porting from 32-bit to 64-bit with fine-tooth comb?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: porting from 32-bit to 64-bit with fine-tooth comb?
Date 2015-02-07 17:22 -0800
Organization None to speak of
Message-ID <lnbnl5jiyo.fsf@nuthaus.mib.org> (permalink)
References <8c0baf78-2ed4-4012-8a87-df42391b5e75@googlegroups.com> <cjnqn5Fbn5tU1@mid.uni-berlin.de>

Show all headers | View raw


jt@toerring.de (Jens Thoms Toerring) writes:
[...]
> Morale: don't attempt to store structures an binary blobs in
> a file if you want to be able to read that data back with any-
> thing else than the exact same program that wrote it. Learned
> it the hard way nearly 20 years ago;-)

It's not *quite* that bad (though it probably doesn't hurt to assume
that it is).

It can be possible to write code that's compatible between 32-bit and
64-bit implementations *if* you pay very very close attention to how
both implementations represent data.

Typically you'll want to define a struct type that has the same layout
on both systems.

You can often allow for differences in the sizes of the predefined types
by using the fixed-size intN_t and uintN_t types.  You can allow for
alignment by laying out the struct members so that neither
implementation inserts padding between them.

If endianness is an issue, you either need to do byte-swapping on one or
both side, or define the structure using only byte arrays.  If you know
that both systems have the same endianness, you might not have to do
that.

There are plenty of binary file formats that can be accessed on multiple
different systems (the various image formats, zip files, etc.)

Of course you *can* easily shoot yourself in the foot if you're not
careful, and if you're able to control the file format, there are
substantial advantages in using some sort of plain text format.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

porting from 32-bit to 64-bit with fine-tooth comb? mbjorn@y7mail.com - 2015-02-07 15:33 -0800
  Re: porting from 32-bit to 64-bit with fine-tooth comb? wssimms@gmail.com - 2015-02-07 16:56 -0800
  Re: porting from 32-bit to 64-bit with fine-tooth comb? jt@toerring.de (Jens Thoms Toerring) - 2015-02-08 00:59 +0000
    Re: porting from 32-bit to 64-bit with fine-tooth comb? Keith Thompson <kst-u@mib.org> - 2015-02-07 17:22 -0800
      Re: porting from 32-bit to 64-bit with fine-tooth comb? jt@toerring.de (Jens Thoms Toerring) - 2015-02-08 01:43 +0000
        Re: porting from 32-bit to 64-bit with fine-tooth comb? raltbos@xs4all.nl (Richard Bos) - 2015-02-08 16:16 +0000
  Re: porting from 32-bit to 64-bit with fine-tooth comb? Richard Damon <Richard@Damon-Family.org> - 2015-02-07 20:02 -0500
  Re: porting from 32-bit to 64-bit with fine-tooth comb? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-02-08 02:18 +0000
  Re: porting from 32-bit to 64-bit with fine-tooth comb? Bartc <bc@freeuk.com> - 2015-02-08 11:08 +0000
  Re: porting from 32-bit to 64-bit with fine-tooth comb? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-02-09 21:20 +0000
  Re: porting from 32-bit to 64-bit with fine-tooth comb? Nobody <nobody@nowhere.invalid> - 2015-02-09 21:35 +0000
  Re: porting from 32-bit to 64-bit with fine-tooth comb? Lőrinczy Zsigmond <nospam@for.me> - 2015-04-03 16:07 +0200
    Re: porting from 32-bit to 64-bit with fine-tooth comb? James Kuyper <jameskuyper@verizon.net> - 2015-04-03 11:21 -0400
    Re: porting from 32-bit to 64-bit with fine-tooth comb? Barry Schwarz <schwarzb@dqel.com> - 2015-04-03 09:36 -0700
      Re: porting from 32-bit to 64-bit with fine-tooth comb? Lőrinczy Zsigmond <nospam@for.me> - 2015-04-03 19:10 +0200
  Re: porting from 32-bit to 64-bit with fine-tooth comb? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-04-04 21:05 +0000
    Re: porting from 32-bit to 64-bit with fine-tooth comb? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-04 23:13 -0700
      Re: porting from 32-bit to 64-bit with fine-tooth comb? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-04-11 04:19 +0000
        Re: porting from 32-bit to 64-bit with fine-tooth comb? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-10 23:53 -0700
          Re: porting from 32-bit to 64-bit with fine-tooth comb? Richard Damon <Richard@Damon-Family.org> - 2015-04-11 10:54 -0400
          Re: porting from 32-bit to 64-bit with fine-tooth comb? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-04-11 15:59 +0000

csiph-web