ANS Forth does not specify the sizes of the data types. Instead, it
offers a number of words for computing sizes and doing address
arithmetic. Basically, address arithmetic is performed in terms of
address units (aus); on most systems the address unit is one byte. Note
that a character may have more than one au, so
chars is no noop
(on systems where it is a noop, it compiles to nothing).
ANS Forth also defines words for aligning addresses for specific types. Many computers require that accesses to specific data types must only occur at specific addresses; e.g., that cells may only be accessed at addresses divisible by 4. Even if a machine allows unaligned accesses, it can usually perform aligned accesses faster.
For the performance-conscious: alignment operations are usually only necessary during the definition of a data structure, not during the (more frequent) accesses to it.
ANS Forth defines no words for character-aligning addresses. This is not an oversight, but reflects the fact that addresses that are not char-aligned have no use in the standard and therefore will not be created.
The standard guarantees that addresses returned by
are cell-aligned; in addition, Gforth guarantees that these addresses
are aligned for all purposes.
Note that the standard defines a word
char, which has nothing to
do with address arithmetic.
charsn1 -- n2 core ``chars''
char+c-addr1 -- c-addr2 core ``care-plus''
cellsn1 -- n2 core ``cells''
cell+a-addr1 -- a-addr2 core ``cell-plus''
cell-- u gforth ``cell''
align-- core ``align''
alignedc-addr -- a-addr core ``aligned''
floatsn1 -- n2 float ``floats''
float+f-addr1 -- f-addr2 float ``float-plus''
float-- u gforth ``float''
falign-- float ``falign''
falignedc-addr -- f-addr float ``f-aligned''
sfloatsn1 -- n2 float-ext ``s-floats''
sfloat+sf-addr1 -- sf-addr2 float-ext ``s-float-plus''
sfalign-- float-ext ``s-f-align''
sfalignedc-addr -- sf-addr float-ext ``s-f-aligned''
dfloatsn1 -- n2 float-ext ``d-floats''
dfloat+df-addr1 -- df-addr2 float-ext ``d-float-plus''
dfalign-- float-ext ``d-f-align''
dfalignedc-addr -- df-addr float-ext ``d-f-aligned''
maxalign-- float ``maxalign''
maxalignedaddr -- f-addr float ``maxaligned''
cfalign-- gforth ``cfalign''
cfalignedaddr1 -- addr2 gforth ``cfaligned''
ADDRESS-UNIT-BITS-- n environment ``ADDRESS-UNIT-BITS''
Go to the first, previous, next, last section, table of contents.