On 8/2/05, Glynn Clements <[EMAIL PROTECTED]> 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.




-- 
cheers,
Vadi
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" 
in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to