root@csmil.umich.edu (Zurich Operator) (02/19/90)
------------- 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. Thanks, From: chymes@fribourg.csmil.umich.edu (Charles Hymes) Path: fribourg.csmil.umich.edu!chymes Charles H.
doug@xdos.UUCP (Doug Merritt) (02/21/90)
In article <1990Feb19.151157.21042@csmil.umich.edu> root@csmil.umich.edu (Zurich Operator) 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 that was me that time (I've been posting this from time to time for years, and I'm certainly not the only one), but here's my version: /* * RoundUp0(N,T) -- yields ceiling 1,2,...,T-1,0 (yields 0 if n % T == 0) * BufRound(BUF) -- given buffer address, rounds up to word boundary */ #define RoundUp0(N,T) ( (T - (((ULONG) N) & (T-1))) & (T-1)) #define BufRound(BUF) &BUF[ RoundUp0(BUF,4) ] /* example usage: */ char buf[ sizeof(struct FileInfoBlock) + 4]; ptr = (struct FileInfoBlock *) BufRound(buf); ---------------------- End of A.F. Drill :-) -------------------------- Doug -- Doug Merritt {pyramid,apple}!xdos!doug Member, Crusaders for a Better Tomorrow Professional Wildeyed Visionary
walker@sas.UUCP (Doug Walker) (02/22/90)
In article <1990Feb19.151157.21042@csmil.umich.edu> root@csmil.umich.edu (Zurich Operator) 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. Yup, it was me - here it is: #define D_S(name, type) char c_##name[sizeof(type)+3];\ type *name = (type *)((long)(c_##name+3) & ~3); ***** =*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)471-6436 = *|. o.| || | o |// Got mole problems? Call Avogadro - 602-1023! ====== usenet: ...mcnc!rti!sas!walker plink: dwalker bix: djwalker
cmcmanis@stpeter.Sun.COM (Chuck McManis) (02/24/90)
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?!"