Previous: Structure Glossary, Up: Structures


6.23.6 Forth200x Structures

The Forth 2012 standard defines a slightly less convenient form of structures. In general (when using field+, you have to perform the alignment yourself, but there are a number of convenience words (e.g., field: that perform the alignment for you.

A typical usage example is:

     0
       field:                   s-a
       faligned 2 floats +field s-b
     constant s-struct

An alternative way of writing this structure is:

     begin-structure s-struct
       field:                   s-a
       faligned 2 floats +field s-b
     end-structure

begin-structure ( "name" – struct-sys 0  ) facility-ext “begin-structure”

end-structure ( struct-sys +n –  ) facility-ext “end-structure”

end a structure started wioth begin-structure

+field ( noffset1 nsize "name" – noffset2  ) facility-ext “plus-field”

Defining word; defines name ( addr1 -- addr2 ), where addr2 is addr1+noffset1. noffset2 is noffset1+nsize. set +field to standard behavior

cfield: ( u1 "name" – u2  ) facility-ext “c-field-colon”

Define a char-sized field

field: ( u1 "name" – u2  ) facility-ext “field-colon”

Define an aligned cell-sized field

2field: ( u1 "name" – u2  ) gforth-0.7 “two-field-colon”

Define an aligned double-cell-sized field

ffield: ( u1 "name" – u2  ) floating-ext “f-field-colon”

Define a faligned float-sized field

sffield: ( u1 "name" – u2  ) floating-ext “s-f-field-colon”

Define a sfaligned sfloat-sized field

dffield: ( u1 "name" – u2  ) floating-ext “d-f-field-colon”

Define a dfaligned dfloat-sized field