BARfly Help - BAR Implementation File Reference - Expressions

  Limitations on pointer usage

The BAR engine restricts how pointers can be used in some expressions, because the safe nature of pointers in BAR script opcodes prevents the implementation file designer from getting “too creative” with pointer usage.

The following rules must be respected when creating, reading from, or writing to pointers:

  • No direct use of address-of operator: It is not possible to get the address of a pointer’s memory (a so-called “pointer to a pointer”).  The “address-of” operator is not allowed on pointer types.
  • No indirect use of address-of operator: The “address-of” operator is not allowed on a data structure that contains pointers, an array of pointers, or an array of structures containing pointers.  A pointer to a structure or other type could otherwise be typecast to some other scalar or structure type, which would permit alternative access to a pointer’s memory.
  • No implicit addresses of pointer-storing arrays: Arrays that are not immediately indexed are supposed to return a pointer to the first element, but if such usage would permit a pointer to a pointer or pointer to a structure containing pointers, usage is prohibited.
  • No member functions for structures with pointers: If a data structure contains a pointer as a member or as a sub-member of an array or substructure, the structure is not allowed to have member functions.  The “this” pointer could otherwise be typecast to some other scalar or structure type, which would permit alternative access to a pointer’s memory.
  • Restriction of pointers from node memory: A pointer type is only allowed to exist in global memory or on the stack.  Node memory cannot store pointer types.
  • Special pointer load/store opcodes:  The ability to load and store a pointer, even if the expression is an L-value, is restricted to specialized opcodes.  The following means are available for accessing pointers:
    • Single Unit: Load or store the pointer as a single-unit global variable, parameter variable, or local variable.
    • Global Array of Pointers: Load from or store to a pointer in a one-dimensional or two-dimensional array of pointers stored in global memory.
    • Global Structure Containing Pointer(s): Load from or store to a pointer in a single-unit structure stored in global memory.
    • Array of Structures Containing Pointer(s): Load from or store to a pointer in an array of structures stored in global memory.

These limitations are not too restrictive because the purpose of functions in implementation files is to support the validation, sizing, and translation of data.  The cost of total freedom with pointers is fundamentally unsafe code.  Due to the fact that improperly parsed binary files routinely produce invalid pointers, BAR prefers safety over total freedom.


  See also:  [Final expression type result] [L-value status gain and loss]
[Overly complex expressions] [Limitations on pointer usage] [Structure member dereference:  bit scan blocks]


BARfly Help Copyright © 2009 Christopher Allen