Yet another ALIGN idea. (some discussion)

flaps at utcs.UUCP flaps at utcs.UUCP
Wed Jul 9 16:10:22 AEST 1986


In article <1038 at ttrdc.UUCP> levy at ttrdc.UUCP (Daniel R. Levy) writes:
>Say if ajr's suggestion were implemented and /usr/include/align.h contained
>something like
>
>#define ALIGNSIZE 4	/* long int */
>
>Now, given an arbitrary char* pointer, how do we tell if it is aligned?

[provides the simple case]

>But... what about a machine where alignments are "screwy," for example they
>wanted doubles to be located at some fixed offset, say 2, from addresses which
>are integral multiples of 4 or 8?

#define OFFSET 2
#define ISALIGNED(p)((p)%4 == 2)


or of course in the usual case:

#define ALIGNSIZE 4
#define OFFSET 0
#define ISALIGNED(p)((p)%4 == 0)

Of course this could be expanded for any other information that a user needed
to know about the alignment.  And since it would all be in an include file, it
would not break any existing programs, and is not truly an addition to the
language.  I think it would be good to put it in the standard.

ajr



More information about the Comp.lang.c mailing list