-
-
Notifications
You must be signed in to change notification settings - Fork 9
POD Assignment
IsaacShelton edited this page Mar 21, 2022
·
1 revision
Sometimes, it's desirable to assign a struct value as just a block of memory.
By default, this is the case, but for structs that have an __assign__
method, the assignment may do something different.
In order to have an assignment always assign values as if they were blocks of memory, the POD
(plain-old-data) keyword can be used after the =
operator.
import basics
pragma ignore_unused
struct Fancy ()
func main {
fancy1 Fancy
fancy2 Fancy = fancy1 // Will call '__assign__(*Fancy, Fancy)' if it exists
fancy3 Fancy = POD fancy1 // Will copy raw unaltered memory
}
func __assign__(this *Fancy, new_value Fancy) {
printf("Custom assignment '__assign__()' was called!\n")
}
Custom assignment '__assign__()' was called!