+FIELD

( n1 n2 "<spaces>name" -- n3 )

Skip leading space delimiters. Parse name delimited by a space. Create a definition for name with the execution semantics defined below. Return n3 = n1 + n2 where n1 is the offset in the data structure before +FIELD executes, and n2 is the size of the data to be added to the data structure. n1 and n2 are in address units.

name Execution:

( addr1 -- addr2 )

Add n1 to addr1 giving addr2.

See:

Rationale:

+FIELD is not required to align items. This is deliberate and allows the construction of unaligned data structures for communication with external elements such as a hardware register map or protocol packet. Field alignment has been left to the appropriate xFIELD: definition.

Implementation:

Create a new field within a structure definition of size n bytes.

: +FIELD  \ n <"name"> -- ; Exec: addr -- 'addr
   CREATE OVER , +
   DOES> @ +
;

ContributeContributions