Skip to content

POD Parameter

IsaacShelton edited this page Mar 21, 2022 · 1 revision

POD (parameters)

Arguments that are marked as POD (plain-old-data), are immune to __pass__ and __defer__ management procedures.

Usage Example

import basics

struct Grenade ()

func __pass__(grenade POD Grenade) Grenade {
    printf("boom!\n")
    return grenade
}

func __defer__(this *Grenade) {
    printf("kaboom!\n")
}

func main {
    grenade Grenade
    test1(grenade)
    test2(grenade)
    
    // __defer__(Grenade) will be called
}

func test1(_grenade Grenade) {
    // __pass__(Grenade) will be called before this
    // __defer__(Grenade) will be called when this function returns
}

func test2(_grenade POD Grenade) {
    // __pass__(Grenade) will NOT be called before this
    // __defer__(Grenade) will NOT be called when this function returns
}
boom!
kaboom!
kaboom!
Clone this wiki locally