← Back to context

Comment by delian66

3 years ago

> No null > The V docs indicate V has references and “in general, V’s references are similar to Go pointers and C++ references”.

The V documentation also has this: https://github.com/vlang/v/blob/master/doc/docs.md#structs-w...

> Structs with references require explicitly setting the initial value to a reference value unless the struct already defines its own initial value.

> Zero-value references, or nil pointers, will NOT be supported in the future, for now data structures such as Linked Lists or Binary Trees that rely on reference fields that can use the value 0, understanding that it is unsafe, and that it can cause a panic.

    struct Node {
        val   int
        left  &Node
        right &Node
    }

    fn main() {
        n := Node { 123, 0, 0 }
        println(n.left)
    }

This is also another example of a program, that would have been perfect as a bug/issue report, so thanks for that I guess.

Edit: filed under https://github.com/vlang/v/issues/14785