assign/2
assign(
+LHS, +Expr)
Evaluates Expr as an arithmetic expression, and stores the value in the memory location and format given by LHS.
integer_8_at(
L_Exp)
integer_16_at(
L_Exp)
unsigned_8_at(
L_Exp)
unsigned_16_at(
L_Exp)
integer_at(
L_Exp)
address_at(
L_Exp)
single_at(
L_Exp)
double_at(
L_Exp)
Can be used to poke data directly into memory. Evaluates L_Exp
in LHS and Expr as arithmetic expressions. The functor
of the first argument describes the type of data to be stored:
integer_8_at/1
will store a signed 8 bit integer, single_at/1
will
store a single precision floating point number, etc. For more structured
ways of doing this, see the Structs and Objects packages.
The only proper addresses that should be assigned to are
ones that are obtained through the foreign interface.
assign/2
is a very primitive built-in and users should
have only very rare occasions to use it. To directly access and change
data structures represented in foreign languages (like C)
users should look at using the Structs and Objects packages.
Both arguments can be unbound at compile time. But it is more efficient if LHS is bound at compile time. Also note that attempting to overwrite improper locations of memory can cause "Segmentation faults" or "Bus errors" and overwriting Prolog memory can result in undesirable behaviour long after the assignment is done.
instantiation_error
type_error
L_Exp in LHS is not a proper arithmetic expressions or
Expr is of a different type than what is specified by
LHS
domain_error
foo.cstatic int counter; int * init_counter() { counter = 0; return &counter; }
foo.plforeign(init_counter, c, init_counter([-address])). get_counter(Counter, Count) :- Count is integer_at(Counter). incr_counter(Counter) :- assign(integer_at(Counter), integer_at(Counter)+1). | ?- init_counter(C), incr_counter(C), get_counter(C, Count1), incr_counter(C), incr_counter(C), get_counter(C, Count2). C = 1418304, Count1 = 1, Count2 = 3 | ?-
library(structs)
,
library(objects)