Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!ENG.SUN.COM!Mitch.Bradley From: Mitch.Bradley@ENG.SUN.COM (Mitch Bradley) Newsgroups: comp.lang.forth Subject: Re: Memory Management/PIC Message-ID: <9106041629.AA13342@ucbvax.Berkeley.EDU> Date: 4 Jun 91 16:21:17 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Mitch Bradley Distribution: world Organization: The Internet Lines: 37 > In BASIS, ALIGNED must be used as a runtime operator, to match the compiled > ALIGNments. I disagree. It is possible to perform the ALIGNED operation at compile time, storing the result either in a constant or in a definition with LITERAL . Here's how I do data structures: : STRUCT 0 ; : CELL: ( offset -name- offset' ) CREATE ALIGNED , CELL+ DOES> @ + ; : CHAR: ( offset -name- offset' ) CREATE , CHAR+ DOES> @ + ; STRUCT CHAR: >FIELDA CELL: >FIELDB CONSTANT /MYSTRUCT CREATE MYSTRUCT1 CHAR q C, ALIGNED 1234 , CREATE MYSTRUCT2 CHAR z C, ALIGNED 5678 , : .MYSTRUCT ( adr -- ) DUP >FIELDA C@ EMIT ( adr ) >FIELDB @ . ; MYSTRUCT1 .MYSTRUCT MYSTRUCT2 .MYSTRUCT This illustrates a fairly typical case in which alignment is required - user-defined data structures with mixed-size fields. All the alignment is done at run time. It can be done without the structure defining words: : .MYSTRUCT ( adr -- ) DUP C@ EMIT ( adr ) [ 1 CHARS ALIGNED ] LITERAL + @ . ; Note that the ALIGNED step is again performed at compile time. Mitch