Go to the first, previous, next, last section, table of contents.

Address arithmetic

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 CREATEd words 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.

chars       n1 -- n2         core       ``chars''

char+       c-addr1 -- c-addr2       core       ``care-plus''

cells       n1 -- n2       core       ``cells''

cell+       a-addr1 -- a-addr2       core       ``cell-plus''

cell       -- u         gforth       ``cell''

align       --         core       ``align''

aligned       c-addr -- a-addr       core       ``aligned''

floats       n1 -- n2       float       ``floats''

float+       f-addr1 -- f-addr2       float       ``float-plus''

float       -- u         gforth       ``float''

falign       --         float       ``falign''

faligned       c-addr -- f-addr       float       ``f-aligned''

sfloats       n1 -- n2       float-ext       ``s-floats''

sfloat+       sf-addr1 -- sf-addr2         float-ext       ``s-float-plus''

sfalign       --         float-ext       ``s-f-align''

sfaligned       c-addr -- sf-addr       float-ext       ``s-f-aligned''

dfloats       n1 -- n2       float-ext       ``d-floats''

dfloat+       df-addr1 -- df-addr2         float-ext       ``d-float-plus''

dfalign       --         float-ext       ``d-f-align''

dfaligned       c-addr -- df-addr       float-ext       ``d-f-aligned''

maxalign       --         float       ``maxalign''

maxaligned       addr -- f-addr         float       ``maxaligned''

cfalign       --         gforth       ``cfalign''

cfaligned       addr1 -- addr2         gforth       ``cfaligned''

ADDRESS-UNIT-BITS       -- n         environment       ``ADDRESS-UNIT-BITS''

Go to the first, previous, next, last section, table of contents.