Article View: comp.sys.amiga.tech
Article #13471Re: file size
From: Eddy Carroll
Date: Fri, 02 Feb 1990 13:16
Date: Fri, 02 Feb 1990 13:16
34 lines
2034 bytes
2034 bytes
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
Technical Details
Message-ID:
<5447@vax1.tcd.ie>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!tcdcs!swift.cs.tcd.ie!vax1.tcd.ie!ecarrollReferences:
<C#YG5#@masalla.fulcrum.bt.co.uk> <5267@vax1.tcd.ie> <1514@sas.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!tcdcs!swift.cs.tcd.ie!vax1.tcd.ie!ecarroll From: ecarroll@vax1.tcd.ie (Eddy Carroll) Newsgroups: comp.sys.amiga.tech Subject: Re: file size Message-ID: <5447@vax1.tcd.ie> Date: 2 Feb 90 13:16:12 GMT References: <C#YG5#@masalla.fulcrum.bt.co.uk> <5267@vax1.tcd.ie> <1514@sas.UUCP> Organization: Computer Laboratory, Trinity College Dublin Lines: 34