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


Groups > comp.lang.c > #57201

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

From Nobody <nobody@nowhere.invalid>
Newsgroups comp.lang.c
Subject Re: porting from 32-bit to 64-bit with fine-tooth comb?
Date 2015-02-09 21:35 +0000
Organization A noiseless patient Spider
Message-ID <pan.2015.02.09.21.35.56.113000@nowhere.invalid> (permalink)
References <8c0baf78-2ed4-4012-8a87-df42391b5e75@googlegroups.com>

Show all headers | View raw


On Sat, 07 Feb 2015 15:33:39 -0800, mbjorn wrote:

> I got this in a mailing list for a FOSS package that I use:
> 
> "Another thing to note when running old code on 64-bit platforms is to
> inspect the struct definitions that are used directly to store or read
> binary data. There's no standard way to guarantee compatibility but gcc
> has a "packed" pragma which should do the right thing combined with
> explicit padding where needed,"
> 
> Is this a problem, that different word lengths can screw up structures? 
> Can unsigned int, for example, change length going from a 32-bit system to
> 64?

It can, but systems with a 64-bit "int" are rare. There are other issues
which are far more common in practice. Such as:

1. "long" is often 32 bits on 32-bit systems and 64 bits on 64-bit systems
(although "64-bit" versions of Windows have a 32-bit long).

2. Pointers are typically 32 bits on 32-bit systems and 64 bits on 64-bit
systems (including Windows).

3. size_t is typically 32 bits on 32-bit systems and 64 bits on 64-bit
systems (including Windows). Passing an int where a size_t is expected is
usually safe (sizeof(int) <= sizeof(size_t), usually). The converse isn't
safe, and a number of standard C functions return a size_t. Converting
that to an int is likely to be safe on a 32-bit platform, but unsafe on a
64-bit platform. Unfortunately, this is all too common.

4. "double" is 64 bits on all "common" platforms, both 32-bit and 64-bit,
but its alignment may differ depending upon architecture. Meaning that a
structure declaration such as

	struct foo {
	    int a;
	    double b;
	    int c;
	};

may be 16 bytes (4+8+4) on one platform but 24 bytes (4+4+8+4+4, each int
being followed by 4 bytes of padding) on another, even if sizeof(int)==4
and sizeof(double)==8 on both. On both 32-bit and 64-bit platforms,
padding is possible but not required; padding is more likely on 64-bit
platforms than on 32-bit platforms.

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