Pointer remove limit
Console program57 lines of .st173 lines of generated C
after remove: 20
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/c"
version = "@latest"
}
}
}main.st
# Language 7.6.9: a pointer to a List element used after remove is accepted and not checked; it
# points at the element that moved into its slot and never reads outside the List. C only: the
# Rust target refuses a List pointer in a function that changes the List (language 14.1.4).
ability "value" "l" {
type = List
of = Int
size = 3
}
ability "add" "A" {
list = ability.value.l
value = 10
}
ability "add" "B" {
list = ability.value.l
value = 20
depends_on = [ability.add.A]
}
ability "function" "show_after_remove" {
locals = [{ name = "lp", type = Pointer, to = Int }]
body = [ability.set.AimList, ability.remove.First, ability.print.AfterRemove]
}
ability "set" "AimList" {
target = lp
value = address_of(ability.value.l[0])
}
ability "remove" "First" {
list = ability.value.l
index = 0
}
ability "print" "AfterRemove" {
message = "after remove: ${value_at(lp)}"
}
ability "call" "Show" {
function = ability.function.show_after_remove
depends_on = [ability.add.B]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.l
+ ability.add.A
+ ability.add.B
+ ability.function.show_after_remove
+ ability.set.AimList
+ ability.remove.First
+ ability.print.AfterRemove
+ ability.call.Show
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.c
To inspect this generated file, select C in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
cd pointer-remove-limit # a folder holding the .st files above
structop init
structop plan
structop apply