Yet another ALIGN idea. (some

aglew at ccvaxa.UUCP aglew at ccvaxa.UUCP
Thu Jul 10 00:46:00 AEST 1986


An alignment constant would not necessarily work, because there are machines
that have unusual alignment restrictions. My favorite is `strictly aligned
power of two sized' - ie. an object of size N must be aligned on a boundary
of 2^ceil(lg(N)), if indexing is to be used to access fields of such an
object.

    Note that malloc(nitems*sizeof(obj)) is conservative for such a beast,
assuming sizeof rounds up correctly, but calloc() can be a bit more
intelligent.

This scheme is strictly size dependent, but screwier schemes are possible.

Since an alignment constant doesn't necessarily work, how about an
alignmentof(object) operator, analagous to sizeof()? At least that'll work
on all architectures that have alignments based on multiples.

Andy "Krazy" Glew. Gould CSD-Urbana.    USEnet:  ihnp4!uiucdcs!ccvaxa!aglew
1101 E. University, Urbana, IL 61801    ARPAnet: aglew at gswd-vms



More information about the Comp.lang.c mailing list