linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kelly Burkhart" <kelly@kkcsm.net>
To: linux-c-programming@vger.kernel.org
Subject: Re: Struct padding (was blank subject)
Date: Wed, 27 Sep 2006 09:19:35 -0500	[thread overview]
Message-ID: <fa1e4ce70609270719l6bdf5902h7606bcfee5958d90@mail.gmail.com> (raw)

On 9/26/06, Kirkwood, David A <DAVID.A.KIRKWOOD@saic.com> wrote:
> I have an application that works perfectly in a 32 bit environment, but
> does not in a 64 bit environment. I believe
>
> The problem has to do with a structure defined as
>
>             Struct  x {
>
>                         Short aaa
>                         Short bbb
>                         Char something[12]
>                         Long lll
>                         Long mmm
>             }
>
> Sorry about the capitalization.... I'm condemned to using exchange /
> outlook.
>
> After the program starts, I look at the  short variables above and they
> are initialized to hex 2020 (both) which are spaces if they were
> characters. Since this structure is initialized with a pointer to is (
> and its components ) I wonder if in the 64 bit environment I have to
> manually pad out the size(s) to even 64 bit boumderies?

How are you initializing the structure?

You usually shouldn't depend on the layout of structures.  There are
cases in which it is necessary, but it is usually better to avoid.  If
you're trying to write the memory region of this structure to a file
on a 32-bit machine and read it on a 64-bit machine it  would be
better to write marshal/unmarshal functions to transform the structure
to/from a platform independent representation.

                 reply	other threads:[~2006-09-27 14:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fa1e4ce70609270719l6bdf5902h7606bcfee5958d90@mail.gmail.com \
    --to=kelly@kkcsm.net \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).