Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: David Konerding <dek@compbio.berkeley.edu>
Subject: Re: Data structure alignment question
Date: Fri, 21 Mar 2003 23:21:44 +0000 (UTC)	[thread overview]
Message-ID: <slrnb7n873.5ge.dek@wuzzy.berkeley.edu> (raw)
In-Reply-To: 8df11a0.0303211248.6d44bd12@posting.google.com

In article <8df11a0.0303211248.6d44bd12@posting.google.com>, Marc S. Gibian wrote:
> David Konerding <dek@compbio.berkeley.edu> wrote in message news:<slrnb7k7on.qv.dek@wuzzy.berkeley.edu>...
>  
>> The "info" pages, which are included with the gcc distribution, have
>> a page on this, "Variable attributes" which explain how to specify the
>> alignment and packing of structures.
> 
> I have attempted to follow these instructions and things still just
> did not seem to work... see below for more details.
>  
>> However, your message seems to suggest that you are writing the binary
>> data of a structure directly over the network.  Is that correct?  If so,
>> you should be aware many people consider this a poor solution because
>> it's not very portable.  I always use some intermediate data encoding
>> which ensures portable behavior (in my case CORBA, but other data
>> encoders exist).
> 
> Rather than get into the merits of binary vs. text based protocols,
> this is not an open issue for my current effort because I am porting
> software that has been around for quite a while, with a significant
> installed base. Thus, we need to avoid changing the protocol to
> maintain compatibility with the existing installed product.

I appreciate your need to maintain protocol compatibility.

However, my point was to avoid taking a struct, and writing it over the
network directly.  Attempting to get a struct to have the alignment of
fields you need by using compiler options is iffy.  Even if you don't use
a platform-neutral data encoder like XDR or CORBA, you can achieve layout
of fields in memory without using structs- you have to do the work by
hand, but this is more reliable and portable.  Effectively, you end up
writing a function which "packs" a struct into a binary representation
that is equivalent to your protocol format, and another function which
"unpacks" a struct.  Is source compatibility still a requirement?
You would have to rewrite some core routines to handle this.

Dave


  reply	other threads:[~2003-03-21 23:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-20  0:36 Data structure alignment question Marc S. Gibian
2003-03-20 16:59 ` Brian Haley
2003-03-20 19:55 ` David Konerding
2003-03-21 20:48   ` Marc S. Gibian
2003-03-21 23:21     ` David Konerding [this message]
2003-03-24 19:49       ` Marc S. Gibian
2003-04-16  1:05         ` Marc S. Gibian
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox