From: "Amit Dang" <amit_dang@intersolutions.stpn.soft.net>
To: Vadiraj <vadiraj.cs@gmail.com>
Cc: linux-c-programming <linux-c-programming@vger.kernel.org>
Subject: Re: Any pointer to Byte Alignment & Structure Padding?
Date: Wed, 3 Aug 2005 09:34:53 +0530 [thread overview]
Message-ID: <043401c597e0$90db3240$9900a8c0@ispl091> (raw)
In-Reply-To: 6eee1c4050802101269ac862b@mail.gmail.com
Reading byte wise won't help any way. Its both reading and writing.
Structure in that case should be written field wise. Moreover in this case
we need to take care of size of different types, floating point format, etc.
Its tough!!
----- Original Message -----
From: "Vadiraj" <vadiraj.cs@gmail.com>
To: "Glynn Clements" <glynn@gclements.plus.com>
Cc: "Amit Dang" <amit_dang@intersolutions.stpn.soft.net>;
"linux-c-programming" <linux-c-programming@vger.kernel.org>
Sent: Tuesday, August 02, 2005 10:42 PM
Subject: Re: Any pointer to Byte Alignment & Structure Padding?
> On 8/2/05, Glynn Clements <glynn@gclements.plus.com> wrote:
> >
> > Amit Dang wrote:
> >
> > > Thanks for the reply. So any idea about how structure should be
defined
> > > in case it is to be used by a text file editor which works on both
linux &
> > > solaris.
> >
> > However you like.
> >
> > You shouldn't be trying to read blocks of data from a file directly
> > into a C "struct" in memory. That technique is fine for "internal"
> > files which only need to be read by one version of the software on one
> > particular platform, but it's the wrong approach for "interchange"
> > files which can be transferred between different systems or different
> > versions of the software.
> >
> > For interchange formats, rather than making assumptions about the
> > size, offset and byte order of structure fields, you should either
> > write your own decoding and encoding routines or use a standard data
> > encoding (e.g. XDR, ASN.1 etc).
>
> May be you could align your structure such a way that compiler does
> not have to do any padding. In that case you would not face any
> problem across different platforms.
>
> for the same example arranging it this way would give 16 bytes on all
> 32 bit compilers..
>
> struct temp
> {
> long long l;
> int i;
> char c;
> char c1;
> }; /* this example would still gets padded at the end. If you could
> avoid this too,
> you are safe */
>
> Best way that I would prefer would be read byte wise and form the
> structure peacefully instead of direct struct read.
next prev parent reply other threads:[~2005-08-03 4:04 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-01 11:43 Any pointer to Byte Alignment & Structure Padding? Amit Dang
[not found] ` <6eee1c40508010514517b5b90@mail.gmail.com>
2005-08-01 12:16 ` Vadiraj
[not found] ` <17134.43470.280296.644313@cerise.gclements.plus.com>
2005-08-02 11:21 ` Vadiraj
2005-08-02 11:40 ` Amit Dang
2005-08-02 16:39 ` Glynn Clements
2005-08-02 17:12 ` Vadiraj
2005-08-03 4:04 ` Amit Dang [this message]
[not found] ` <673ac06405080402432d0feda3@mail.gmail.com>
2005-08-04 15:23 ` Vadiraj
2005-08-04 16:28 ` Steve Graegert
2005-08-05 16:51 ` Vadiraj
2005-08-05 4:14 ` Amit Dang
2005-08-05 6:32 ` Steve Graegert
2005-08-05 6:49 ` Amit Dang
2005-08-05 7:09 ` Steve Graegert
2005-08-05 11:19 ` Glynn Clements
2005-08-05 10:15 ` Steve Graegert
2005-08-05 10:53 ` Amit Dang
2005-08-05 11:13 ` Steve Graegert
2005-08-05 11:28 ` Amit Dang
2005-08-05 11:37 ` Steve Graegert
2005-08-05 12:59 ` Glynn Clements
2005-08-05 11:31 ` Steve Graegert
2005-08-01 12:27 ` Amit Dang
2005-08-01 14:11 ` wwp
[not found] ` <003b01c59715$d3ffef00$9900a8c0@ispl091>
[not found] ` <6a00c8d5050801234267dd0f7f@mail.gmail.com>
[not found] ` <01dd01c5972f$5c3b62a0$9900a8c0@ispl091>
[not found] ` <17135.20687.821822.269575@cerise.gclements.plus.com>
[not found] ` <02c401c59745$2aaa0410$9900a8c0@ispl091>
2005-08-02 11:08 ` Progga
2005-08-02 11:34 ` Amit Dang
2005-08-02 11:32 ` Steve Graegert
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='043401c597e0$90db3240$9900a8c0@ispl091' \
--to=amit_dang@intersolutions.stpn.soft.net \
--cc=linux-c-programming@vger.kernel.org \
--cc=vadiraj.cs@gmail.com \
/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).