Alignment issues using the Sun C++ compiler SC4.2

Alignment issues using the Sun C++ compiler SC4.2

Post by Casper H.S. Dik - Network Security Engine » Wed, 23 Apr 1997 04:00:00




>What is the way to change the default alignment
>properties of the data in your C++ program, when
>using SunWorks SC4.2 compiler? Can I do this on a
>per file basis, rather that for each class/struct?

You don't want to mess with aligment, if you use it to
exchange data, you're barking up the wrong tree.
Checkout XDR instead and find that tehre's much more than
aligment to data exchange.

And when it comes to C++ classes, forget about exchanging
those between unlike systems, the compilers will wildly disagree
about how classes are laid out.

Quote:>I mean something of the sort of the __attribute__()
>compiler specific instruction for ther GNU C++ compiler,
>or #pragma pack(), for the Microsoft C++ compiler.

There's a pragma pack, but after that your code wil run slowly.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

Alignment issues using the Sun C++ compiler SC4.2

Post by Ivailo Ivano » Wed, 23 Apr 1997 04:00:00


Hi,

What is the way to change the default alignment
properties of the data in your C++ program, when
using SunWorks SC4.2 compiler? Can I do this on a
per file basis, rather that for each class/struct?

I mean something of the sort of the __attribute__()
compiler specific instruction for ther GNU C++ compiler,
or #pragma pack(), for the Microsoft C++ compiler.

Thanks.

--
Ivailo Ivanov
Seagate Software, Information Management Group


 
 
 

Alignment issues using the Sun C++ compiler SC4.2

Post by Ivailo Ivano » Thu, 24 Apr 1997 04:00:00



Quote:

> You don't want to mess with aligment, if you use it to
> exchange data, you're barking up the wrong tree.
> Checkout XDR instead and find that tehre's much more than
> aligment to data exchange.

> And when it comes to C++ classes, forget about exchanging
> those between unlike systems, the compilers will wildly disagree
> about how classes are laid out.

> There's a pragma pack, but after that your code wil run slowly.

> Casper

Thanks a lot. I am aware of the problems you are mentioning
above, but I need that in order to read binary data created
on another platform (already created on an Intel based machines,
so XDR doesn't help). What I intend to do is have 2 data structures
for each single binary data strucrure: one packed and one not. And
the first thing I will do after reading is copy from the first
into the second.

Anyway, thanks for the quich response.

--
Ivailo Ivanov
Seagate Software, Information Management Group

 
 
 

Alignment issues using the Sun C++ compiler SC4.2

Post by Guy Harr » Thu, 24 Apr 1997 04:00:00



Quote:>Thanks a lot. I am aware of the problems you are mentioning
>above, but I need that in order to read binary data created
>on another platform (already created on an Intel based machines,
>so XDR doesn't help).

Unless the platform on which you're running is also little-endian (i.e.,
Solaris x86 - or Solaris for PowerPC, if it was ever made available),
"#pragma pack()" won't be sufficient.  You'll have to byte-swap integral
quantities longer than 1 byte - in which case, you could, instead, just
read the binary data structures into something consisting solely of one
or more arrays of "unsigned char", and do the copy-and-byte-swap by
hand (you'd have to do the byte-swap by hand anyway, unless you have a
tool to automatically generate that code - in which case you might be
able to make it generate code that just extracts bytes, one at a time,
in the right order, from >1-byte fields).
 
 
 

Alignment issues using the Sun C++ compiler SC4.2

Post by Bryan Altha » Thu, 24 Apr 1997 04:00:00



: >
: >
: > You don't want to mess with aligment, if you use it to
: > exchange data, you're barking up the wrong tree.
: > Checkout XDR instead and find that tehre's much more than
: > aligment to data exchange.
: >
: > And when it comes to C++ classes, forget about exchanging
: > those between unlike systems, the compilers will wildly disagree
: > about how classes are laid out.
: >
: > There's a pragma pack, but after that your code wil run slowly.
: >
: > Casper
:
: Thanks a lot. I am aware of the problems you are mentioning
: above, but I need that in order to read binary data created
: on another platform (already created on an Intel based machines,
: so XDR doesn't help). What I intend to do is have 2 data structures
: for each single binary data strucrure: one packed and one not. And
: the first thing I will do after reading is copy from the first
: into the second.
:
You may want to check out ObjectSpace's Streaming<ToolKit>. This might
be useful if the files on the other platform can be created using
this toolkit and read back in on the Sun using this toolkit.

http://www.objectspace.com/Products/cpp_libraries/streamingtk/streami...

Streaming<ToolKit> contains a set of classes that provide:

 - Object persistence and transport
 - Easily store and retrieve objects to and from files, as well as send
   objects across TCP sockets or other devices to another computer.
 - IOStream interfaces
 - Use familiar text streaming interfaces and manipulators on a variety of I/O
   devices, such as TCP sockets