Representation Clauses

Doug Gwyn gwyn at smoke.brl.mil
Thu Feb 14 08:49:29 AEST 1991


In article <91042.160311KKEYTE at ESOC.BITNET> KKEYTE at ESOC.BITNET (Karl Keyte) writes:
>How flexible are ANSI?  I.e. is 'C's standardisation fixed?

Yes, the standard was approved by ANSI in late 1989 and is not
expected to undergo revision (apart from possible ISO addenda,
which are not attempting to make changes of the sort that you
suggest) for several years to come.

>I feel that 'C' is missing data alignment representation clauses in
>structures.  I would like to be able to do something like:
>  struct ALIGN_TEST
>  {
>     int       a      at 0;
>     char      b      at 4;
>     float     c      at 8;
>  }
>in order to force the offset of the elements.  This then enables
>structures to provide truly portable messages on machines with
>different structure alignments.  For example, the above structure
>is not the same on a Sun-3 and a Sun-4 (Sparc).

Ideas along these lines were submitted during preparation of the
ANSI C standard, and were rejected by the committee.  There are
at least two significant problems with the idea, one being that
it is an innovation, not existing practice, the other being that
it doesn't provide the portable message structure that you think
it does.  You can insert padding by use of dummy fields, but the
most difficult issues for binary data interchange between
heterogeneous architectures are much deeper than mere alignment
of fields.  Sun invented the XDR protocols to deal with them, for
one concrete example worthy of study.



More information about the Comp.std.c mailing list