Oppolzer - Informatik / Blog


Blog-Hauptseite      Neuester Artikel      Älterer Artikel      Neuerer Artikel      Älterer gleiche Kategorie      Neuerer gleiche Kategorie

IBM-MAIN - Ausrichtung von Strukturkomponenten (bei C bzw. PL/1)

Subject:

Re: A possible bug in the IBM Runtimne C library

From:

Bernd Oppolzer <bernd.oppolzer@T-ONLINE.DE>

Reply-To:

IBM Mainframe Discussion List <IBM-MAIN@LISTSERV.UA.EDU>

Date:

2015.02.23 08:37:55


Hello Z.,

unless the structure is defined with the nonstandard extension Packed (or
_Packed, I don't recall it exactly), all ints or longs will be aligned on a 4
byte boundary, that is, in a sequence of int, short, int, short, you will get
two padding bytes after every short field (which is in fact 2 bytes long).

Same goes for PL/1 with a sequence of BIN FIXED(31) and BIN FIXED(15) fields.
The rules for alignment with PL/1 are more complicated than with C. Structures
in C always start with the highest needed alignment required inside the
structure, while in PL/1 there is some work done to start the structure at an
offset which minimizes the padding bytes in the middle of the structure (short
story, the long explanation in the PL/1 books needs many pages).

You can synchronize alignment between PL/1 and C, if you put a dummy double
precision field (which has alignment requirement of 8) in front of the
structure.  Then the two languages do the same.  A similar technique should work
for COBOL, too.

Kind regards

Bernd



Am 23.02.2015 um 03:44 schrieb Z.A.:
> __off_t is clearly defined earlier as a 32 bit entity but mbstate_t is defined
> as short which I assumed is a 16 bit entity.  Either short is NOT 16 bits
> but 32 bit entity as well, or the C compiler leaves 2 bytes of zeroes in order
> to keep the correct integral boundary.  However, in REAL LIFE there are 32 bits
> between rm_so and rm_eo.  I did not bother to investigate too much ...

Blog-Hauptseite      Neuester Artikel      Älterer Artikel      Neuerer Artikel      Älterer gleiche Kategorie      Neuerer gleiche Kategorie