[comp.sys.amiga.tech] file size

ecarroll@vax1.tcd.ie (Eddy Carroll) (02/02/90)

In article <1514@sas.UUCP>, walker@sas.UUCP (Doug Walker) writes:
> In article <5267@vax1.tcd.ie> ecarroll@vax1.tcd.ie (Eddy Carroll) writes:
>> Because AmigaDOS uses BPTR's whenever possible, it requires that the fib
>> structure you pass to it is longword aligned. To ensure this, you need to
>> allocate the fib structure via a call to AllocMem (which always guarantees
>> longword alignment). Doing this, the above code becomes:
> 
> Ah, but you DON'T need to AllocMem it!  How about this:
> 
> #define WORDROUND(xxx) (((long)xxx+3)>>2)<<2)   /* Round to word boundary */
> #define D_S(name, type) char c_##name[sizeof(type)+3]; \
>                         type *name = (type *)WORDROUND(c_##name);
> 
> void foo()
> {
>    D_S(fib, struct FileInfoBlock);
> ...
>    Examine(lock, fib);
>    printf("%d\n", fib->fib_Size);
> }
> 
> [ ... ]

That's a nice neat way of doing it, which certainly makes the code a lot
tidier (except for the macro definition which looks horrible :-)  One of
the two alternative methods to AllocMem()ing that I hinted at in my original
article was similar to this except I didn't think of using a macro to
hide the nastiness. (The other way is to declare the fib as a global, and
make sure that all the globals declared before it occupy an exact number of
longwords; very kludgy, but probably works fine).
-- 
Eddy Carroll             ----* Genuine MUD Wizard  | "You haven't lived until
INTER: ecarroll@vax1.tcd.ie                        |    you've died in MUD!"
 UUCP: {..uunet}!mcvax!ukc!vax1.tcd.ie!ecarroll    |  -- Richard Bartle