two byte alignment...how???

two byte alignment...how???

Post by Tony R. Benne » Tue, 27 Jun 2000 04:00:00



We have some code common between a Tandem system and an RS6000.

Unfortunately, the tandem has two byte alignment and the rs6000 has
4 byte alignment.

One structure is sent between the two systems... and of course alignment
has become an issue.

Is there a way, via a pragma or whatever, to define a structure for use
between the two systems, that has two byte alignment...
...specifically, the results of the sizeof(structure common_struct),
needs to be the same???

TIA,
-tony
--


 
 
 

two byte alignment...how???

Post by Anthony Johnso » Tue, 27 Jun 2000 04:00:00


Why not just add a 2-byte padding to the structure so both data elements allign the
same?


> We have some code common between a Tandem system and an RS6000.

> Unfortunately, the tandem has two byte alignment and the rs6000 has
> 4 byte alignment.

> One structure is sent between the two systems... and of course alignment
> has become an issue.

> Is there a way, via a pragma or whatever, to define a structure for use
> between the two systems, that has two byte alignment...
> ...specifically, the results of the sizeof(structure common_struct),
> needs to be the same???

> TIA,
> -tony
> --



--
----------------------------------------------
Anthony Johnson         1-619-282-6300
Storix Software         1-619-282-4506 (fax)


 
 
 

two byte alignment...how???

Post by Tony R. Benne » Wed, 28 Jun 2000 04:00:00




>Why not just add a 2-byte padding to the structure so both data elements allign the
>same?


>> We have some code common between a Tandem system and an RS6000.

>> Unfortunately, the tandem has two byte alignment and the rs6000 has
>> 4 byte alignment.

>> One structure is sent between the two systems... and of course alignment
>> has become an issue.

>> Is there a way, via a pragma or whatever, to define a structure for use
>> between the two systems, that has two byte alignment...
>> ...specifically, the results of the sizeof(structure common_struct),
>> needs to be the same???

Sorry, but in our environment the Tandem is the BigDog...
...we're just along for the ride... we have to share their structures
using the Tandem alignment!!!

So, I have to make AIX have the same value as the Tandem does
for things like this:

        struct xxx
        {
            long  xxx1;
            long  xxx2;
            short xxx3;
        };

        sizeof(struct xxx) == 10 (Tandem's value)
        sizeof(struct xxx) == 12 (AIX's value)

TIA,
Tony

--


 
 
 

two byte alignment...how???

Post by James Carlso » Thu, 29 Jun 2000 04:00:00



Quote:> Sorry, but in our environment the Tandem is the BigDog...
> ...we're just along for the ride... we have to share their structures
> using the Tandem alignment!!!

OK.

Quote:> So, I have to make AIX have the same value as the Tandem does
> for things like this:

>    struct xxx
>    {
>        long  xxx1;
>        long  xxx2;
>        short xxx3;
>    };

>    sizeof(struct xxx) == 10 (Tandem's value)
>    sizeof(struct xxx) == 12 (AIX's value)

Code that depends on structure packing is, quite frankly, broken.  It
should be rewritten to avoid depending on unspecified parts of the
language.

That being said, use "-qalign=packed" for IBM's xlC, or
"-fpack-struct" for gcc.

Don't be surprised if the rest of the world completely falls apart
when you do this, however.  Many system interfaces silently depend on
having normal alignment.

--

SUN Microsystems / 1 Network Drive         71.234W   Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757   42.497N   Fax +1 781 442 1677
"PPP Design and Debugging" --- http://people.ne.mediaone.net/carlson/ppp

 
 
 

two byte alignment...how???

Post by Tony R. Benne » Fri, 30 Jun 2000 04:00:00




 >Add '#pragma options align=twobyte' before the struct and
 >'#pragma options align=reset' after the struct.  This will change the
 >alignment rules
 >for just one structure.  The -qalign=packed option changes it for
 >everything.  Also keep in mind that the twobyte alignment rules (which is
 >really the same as mac68k) might have different rules regarding bitfields
 >than the Tandem system.
 >
 >

 >> > Sorry, but in our environment the Tandem is the BigDog...
 >> > ...we're just along for the ride... we have to share their structures
 >> > using the Tandem alignment!!!
 >>
 >> OK.
 >>
 >> > So, I have to make AIX have the same value as the Tandem does
 >> > for things like this:
 >> >
 >> >       struct xxx
 >> >       {
 >> >           long  xxx1;
 >> >           long  xxx2;
 >> >           short xxx3;
 >> >       };
 >> >
 >> >       sizeof(struct xxx) == 10 (Tandem's value)
 >> >       sizeof(struct xxx) == 12 (AIX's value)
 >>
 >> Code that depends on structure packing is, quite frankly, broken.  It
 >> should be rewritten to avoid depending on unspecified parts of the
 >> language.
 >>
 >> That being said, use "-qalign=packed" for IBM's xlC, or
 >> "-fpack-struct" for gcc.
 >>
 >> Don't be surprised if the rest of the world completely falls apart
 >> when you do this, however.  Many system interfaces silently depend on
 >> having normal alignment.
 >>
 >> --

 >> SUN Microsystems / 1 Network Drive         71.234W   Vox +1 781 442 2084
 >> MS UBUR02-212 / Burlington MA 01803-2757   42.497N   Fax +1 781 442 1677
 >> "PPP Design and Debugging" --- http://people.ne.mediaone.net/carlson/ppp
 >
 >--
 >Sean Perry

 >
 >

Sean,
        Thanks, I'll try it at work tomorrow...

-tony
--


 
 
 

two byte alignment...how???

Post by Sean Perr » Sat, 01 Jul 2000 04:00:00


Add '#pragma options align=twobyte' before the struct and
'#pragma options align=reset' after the struct.  This will change the
alignment rules
for just one structure.  The -qalign=packed option changes it for
everything.  Also keep in mind that the twobyte alignment rules (which is
really the same as mac68k) might have different rules regarding bitfields
than the Tandem system.



> > Sorry, but in our environment the Tandem is the BigDog...
> > ...we're just along for the ride... we have to share their structures
> > using the Tandem alignment!!!

> OK.

> > So, I have to make AIX have the same value as the Tandem does
> > for things like this:

> >       struct xxx
> >       {
> >           long  xxx1;
> >           long  xxx2;
> >           short xxx3;
> >       };

> >       sizeof(struct xxx) == 10 (Tandem's value)
> >       sizeof(struct xxx) == 12 (AIX's value)

> Code that depends on structure packing is, quite frankly, broken.  It
> should be rewritten to avoid depending on unspecified parts of the
> language.

> That being said, use "-qalign=packed" for IBM's xlC, or
> "-fpack-struct" for gcc.

> Don't be surprised if the rest of the world completely falls apart
> when you do this, however.  Many system interfaces silently depend on
> having normal alignment.

> --

> SUN Microsystems / 1 Network Drive         71.234W   Vox +1 781 442 2084
> MS UBUR02-212 / Burlington MA 01803-2757   42.497N   Fax +1 781 442 1677
> "PPP Design and Debugging" --- http://people.ne.mediaone.net/carlson/ppp

--
Sean Perry