
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses




Task

Demonstrate how to get the address of a variable and how to set the address of a variable.




package require critcl
# This code assumes an ILP32 architecture, like classic x86 or VAX.
critcl::cproc peek {int addr} int {
    union {
       int i;
       int *a;
    } u;
 
    u.i = addr;
    return *u.a;
}
critcl::cproc poke {int addr int value} void {
    union {
        int i;
        int *a;
    } u;
 
    u.i = addr;
    *u.a = value;
}
package provide poker 1.0