Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!lll-crg!gymble!umcp-cs!chris From: chris@umcp-cs.UUCP Newsgroups: net.lang.c Subject: Re: Yet another ALIGN idea. Message-ID: <2355@umcp-cs.UUCP> Date: Sat, 12-Jul-86 00:14:04 EDT Article-I.D.: umcp-cs.2355 Posted: Sat Jul 12 00:14:04 1986 Date-Received: Sat, 12-Jul-86 06:22:15 EDT References: <1038@ttrdc.UUCP> <2600066@ccvaxa> Reply-To: chris@maryland.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 30 In article <2600066@ccvaxa> aglew@ccvaxa.UUCP writes: >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. I think this can still be implemented with a common header file, e.g., #define OFFSET_TO_ALIGN(ptr) /*something*/ #define IS_ALIGNED(ptr) (OFFSET_TO_ALIGN(ptr) == 0) On a Vax, and purely for efficiency, /*something*/ is #define OFFSET_TO_ALIGN(ptr) ((4 - (int) (ptr)) & 3) On a Pyramid, the same `define' works; on a Sun, it can be reduced to #define OFFSET_TO_ALIGN(ptr) ((int) (ptr) & 1) On your hypothetical machine, /*something*/ may be #define OFFSET_TO_ALIGN(ptr) (_offset_to_align(sizeof *(ptr))) where _offset_to_align is a library function. (N.B.: That it *can* be done this way does not mean that it *must* be done this way.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu