Making a Programming Language From Scratch/Pointers
Introduction to pointers[edit | edit source]
Pointers are variables that store the addresses of other variables. This variable is generally a DWORD or a 32-bit integer, however the variable the address of which the pointer is storing can be of any type. Pointers are used extensively to pass static or local variables to be edited and are the major type of arguments provided to a void function.
Pointer Format[edit | edit source]
The following is the traditional C and C++ format to declare pointer variables.
[type of variable of which the pointer is storing value of][*(represents pointer)][variable name][initialization of pointer][,|;]
Note that pointer variables can be declared among the variable type of which it is storing the value. Example:
The & operator provides the address of the variable rather than the value stored in it.
Algorithm for declaration[edit | edit source]
The algorithm for this is as follows:
1. If character be * then go through following steps else skip it. 2. Get name of variable. 3. If next character not be = then write to .data section as [name of variable] ptr [type] ? 4. Else get value. Remove first character as it will be &. Write to .data? section as [name of variable] ptr [type] [value]. 5. Repeat step 1.