Override (an intended overlap of a fixed location)

Sometimes two variables are meant to use the same RAM: parts of a program that are never in use at the same time can be purposely allocated to the same locations, to make the most of a chip’s RAM. Override, written straight after At location, tells the compiler that the overlap is intended, so the warning is not shown for that variable:

    // A 512-byte buffer that is only used while USB is running ...
    Dim USBBuffer As Alloc * 512 At 0x400 Override

    // ... and a file list that is only used while USB is not running, in the same RAM
    Dim FileNames(768) As Byte At 0x400 Override
    Dim FileKinds(64) As Byte At 0x400 + 769 Override
  • Override applies to the one Dim it is written on. Every Dim in an intended overlap must say Override itself - the first one too: the compiler, not the order in the source, decides which variable is given the location first, and the warning is shown for the others. A Dim that overlaps without Override still gives the warning, so an accidental overlap is not hidden.
  • Override must follow At location. Written without At, it is an error: OVERRIDE can only follow AT <location> in a DIM.
  • With an initial value, Override comes before it: Dim Counter As Byte At 0x400 Override = 0.
  • The location can be a calculation of constants, such as At USB_RAM_START + 769. Writing every overlapping location relative to one constant keeps the layout correct when that constant changes.
  • The compiler cannot know when each part is in use: making sure the overlapping variables are never needed at the same time is up to the program.