Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!drutx!houxe!hogpc!houti!ariel!vax135!cornell!uw-beaver!tektronix!hplabs!hpda!fortune!amd!decwrl!decvax!cca!ima!ism780b!jim From: jim@ism780b.UUCP Newsgroups: net.lang.c Subject: Re: what about alignment problems? - (nf) Message-ID: <12@ism780b.UUCP> Date: Wed, 1-Aug-84 00:31:27 EDT Article-I.D.: ism780b.12 Posted: Wed Aug 1 00:31:27 1984 Date-Received: Sun, 22-Jul-84 03:04:37 EDT Lines: 37 #R:watmath:-831800:ism780b:25500006:000:1184 ism780b!jim Jul 14 12:38:00 1984 Try struct _aschar {char _cchar; char _achar;}; struct _asshort {char _cshort; short _ashort;}; struct _asint {char _cint; int _aint;}; struct _aslong {char _clong; long _along;}; struct _asfloat {char _cfloat; float _afloat;}; struct _asdouble {char _cdouble; double _adouble;}; struct _asptr {char _cptr; char * _aptr;}; #define QUOTE(x)x #define alignof(t) ( (int)&((struct QUOTE(_as)t *)0)->QUOTE(_a)t ) main(){ printf("%d %d %d %d %d %d %d\n", alignof(char), alignof(short), alignof(int), alignof(long), alignof(float), alignof(double), alignof(ptr)); } Admittedly, ptr is a hack and assumes all pointers have the same alignment requirement (more likely than that they all have the same size), and it would be a lot cleaner if alignof were in the language. While we are at it, what would be even more useful would be typeof, especially if it could be used in declarations, so you could do /* declaration with initialization */ typeof(foo) foosave = foo; or #define acopyof(foo) ( *(typeof(foo) *) \ memcpy(malloc(sizeof(foo)), (char *)&(foo), sizeof(foo)) ) -- Jim Balter, INTERACTIVE Systems (ima!jim)