Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!snorkelwacker!apple!sun-barr!newstop!sun!stpeter!cmcmanis From: cmcmanis@stpeter.Sun.COM (Chuck McManis) Newsgroups: comp.sys.amiga.tech Subject: Re: The Long Align Struct Macro D_S Keywords: Long word align, diskInfo struct BCPL Message-ID: <132194@sun.Eng.Sun.COM> Date: 23 Feb 90 21:39:13 GMT References: <1990Feb19.151157.21042@csmil.umich.edu> Sender: news@sun.Eng.Sun.COM Reply-To: cmcmanis@sun.UUCP (Chuck McManis) Organization: Sun Microsystems, Mountain View Lines: 33 In article <1990Feb19.151157.21042@csmil.umich.edu> root@csmil.umich.edu writes: >A few weeks ago somone posted a little macro that could be used in place of >the AllocMem() function to long align structures for use with Amigados commands >like Examine. I lost my copy of this macro when I upgraded to Manx 5.0 >If you have a copy or remember it, I would be most greatful. I don't think it was me, but the technique I use occasionally is as follows: /* Find the size of something in words (guaranteed alignment) */ #define WORDSIZE(s) (((s)+1)/sizeof(short) + 1) /* Align it to a long word boundary */ #define ALIGNED(a) ((((long)(a) & 3) == 0) ? (a) : (long)(a) + 2) The first macro will always get one more word of memory than you actually need, this allows for the array to be aligned on an odd word. If we shift our pointer by one word we will still have enough space for our structure or whatever. To use in a program do something like this ... /* Get enough space for a FileInfoBlock structure + 1 word */ short buf[WORDSIZE(sizeof(struct FileInfoBlock))]; struct FileInfoBlock *fi = ALIGNED(buf); /* Assign fi to the long word aligned address of buf (either &buf[0] or * a &buf[1]. */ --Chuck McManis uucp: {anywhere}!sun!cmcmanis BIX: cmcmanis ARPAnet: cmcmanis@Eng.Sun.COM These opinions are my own and no one elses, but you knew that didn't you. "If it didn't have bones in it, it wouldn't be crunchy now would it?!"