Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What happens when you mutate the target of a pointer to the same memory as the target of an "immutable" reference (eg. function parameters and union switches)?


If I understand correctly, procedure parameters are only immutable in the scope of the procedure because the compiler will decide wether to pass them by value or reference.

At the calling scope, the parameter passed is not immutable. You can pass a pointer too, if you want.

There's also this pattern:

    name := name
which redeclares name in the current scope and shadows the name that exists in the outer scope

    call :: proc(b: int) {
        fmt.println(b)
        // c := &b // illegal!
        // b = 10 // illegal!
        b := b
        b = 10;
        fmt.println(b)
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: