Giter Site home page Giter Site logo

Comments (7)

medvednikov avatar medvednikov commented on May 21, 2024 2

For instance, is it possible to do the following?

p := Point{10,10}
pointer := &p
println(pointer.x, pointer.y)

Yes

Why is it that a struct that is declared and initialized without the mut keyword can be passed into a receiver which will modify the fields of that struct?

This is a mistake in the docs. Fixed. Thanks :)

from v.

ntrel avatar ntrel commented on May 21, 2024

Yes

OK, so V must prevent pointers to stack allocated structs from escaping when passed to a function. Is there an attribute e.g. @escape for marking function parameters as escapable (i.e. assigned to a receiver)?

struct S1 { s2 S2*}
fn (mut S1 s1) set_field(s2 @escape S2*) {s1.s2 = s2}

from v.

medvednikov avatar medvednikov commented on May 21, 2024

from v.

ntrel avatar ntrel commented on May 21, 2024

@medvednikov I presume you mean you don't want an @escape attribute, and all function parameters can't escape. This seems to work against the nice feature of immutable data that it can be referenced in multiple places (and even across threads) because it doesn't change. But I suppose that requires garbage collection or reference counting for heap allocated immutable data.

from v.

medvednikov avatar medvednikov commented on May 21, 2024

from v.

ntrel avatar ntrel commented on May 21, 2024

I think V should prevent escapes for now, then later the restriction could be relaxed in certain cases if necessary. Otherwise it will be hard to go the other way and allow escaping now, then break code by imposing a restriction later. I guess the workaround for forcing escapes (that the programmer knows are memory safe) would be to drop into C #s1->s2 = s2.

from v.

medvednikov avatar medvednikov commented on May 21, 2024

Closing because the original questions were answered.

Escaping structs were discussed in another issue. Basically they will behave like in Go.

from v.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.