Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Pointer (computer programming)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Simulation using an array index== It is possible to simulate pointer behavior using an index to an (normally one-dimensional) array. Primarily for languages which do not support pointers explicitly but ''do'' support arrays, the [[Array data type|array]] can be thought of and processed as if it were the entire memory range (within the scope of the particular array) and any index to it can be thought of as equivalent to a [[general-purpose register]] in assembly language (that points to the individual bytes but whose actual value is relative to the start of the array, not its absolute address in memory). Assuming the array is, say, a contiguous 16 [[megabyte]] character [[data structure]], individual bytes (or a [[String (computer science)|string]] of contiguous bytes within the array) can be directly addressed and manipulated using the name of the array with a 31 bit unsigned [[integer]] as the simulated pointer (this is quite similar to the ''C arrays'' example shown above). Pointer arithmetic can be simulated by adding or subtracting from the index, with minimal additional overhead compared to genuine pointer arithmetic. It is even theoretically possible, using the above technique, together with a suitable [[instruction set simulator]] to simulate ''any'' [[machine code]] or the intermediate ([[byte code]]) of ''any'' processor/language in another language that does not support pointers at all (for example [[Java (programming language)|Java]] / [[JavaScript]]). To achieve this, the [[binary numeral system|binary]] code can initially be loaded into contiguous bytes of the array for the simulator to "read", interpret and execute entirely within the memory containing the same array. If necessary, to completely avoid [[buffer overflow]] problems, [[bounds checking]] can usually be inserted by the compiler (or if not, hand coded in the simulator).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)