-
-
Notifications
You must be signed in to change notification settings - Fork 9
Data Flow Annotations
IsaacShelton edited this page Mar 21, 2022
·
1 revision
Sometimes when procedures take pointer arguments, it can ambiguous whether the programmer intends on only reading from, only writing too, or both reading from and writing to the pointer.
In order to avoid ambiguity, data flow annotations can be used to explicitly state the intention of how a pointer argument will be used. Data flow annotations are NOT enforced, and only exist to help the reader.
There are three types of data flows:
-
in- The pointer is only to be read from -
out- The pointer is only to be written to -
inout- The pointer is for both writing to and reading from
struct Vector2f(x, y float)
func diagonalDistance(in v *Vector2f) float {
return sqrtf(v.x * v.x + v.y * v.y)
}
func getFavoriteColor(out r, g, b *int) {
*r = 255
*g = 255
*b = 255
}
func squareTheNumber(inout value *int) {
*value *= *value
}