Comments (7)
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.
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.
from v.
@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.
from v.
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.
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)
- Optional type matches incorrectly in $for field
- error: invalid operand types for binary operation, error: invalid aggregate type for register load HOT 2
- documentation generator seems to be off
- autofree: memory leak HOT 1
- Buffered Reader read_line() segfault when compiled with -prod HOT 4
- Strange error message with `@[flag]` enum
- `@[flag]` enums should support all 4 bitwise operators, instead of only 2
- add .args to compile time method HOT 4
- fmt: `i++ $if abc ? {` gets formatted, as `i++$ if abc ? {`, and fails to parse.
- typed fns do not match correctly in compile time code
- libpthread linked always HOT 2
- outdated official toml test
- cgen: direct assigning `string` to `?string` with `-autofree`
- cgen: Failed to convert a return of or{}
- support `flag_var<bitwise_operator>= .enum_flag`
- Builder C error: '_t1' undeclared
- Builder C error : identifier expected
- Incorrect f64 -> u64 conversions HOT 5
- compile-time reflection error for enum/struct declared in other module HOT 1
- fixed array: `contains` method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from v.