1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: fix links to attributes (#16301)

This commit is contained in:
kahsa 2022-11-03 14:02:01 +09:00 committed by GitHub
parent 1ecf7c6e41
commit 509f5c7db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2075,7 +2075,7 @@ struct Foo {
} }
``` ```
You can mark a struct field with the `[required]` attribute, to tell V that You can mark a struct field with the `[required]` [attribute](#attributes), to tell V that
that field must be initialized when creating an instance of that struct. that field must be initialized when creating an instance of that struct.
This example will not compile, since the field `n` isn't explicitly initialized: This example will not compile, since the field `n` isn't explicitly initialized:
@ -4534,7 +4534,7 @@ the compiler would complain about the assignment in `f()` because `s` *"might
refer to an object stored on stack"*. The assumption made in `g()` that the call refer to an object stored on stack"*. The assumption made in `g()` that the call
`r.f(&s)` would only borrow the reference to `s` is wrong. `r.f(&s)` would only borrow the reference to `s` is wrong.
A solution to this dilemma is the `[heap]` attribute at the declaration of A solution to this dilemma is the `[heap]` [attribute](#attributes) at the declaration of
`struct MyStruct`. It instructs the compiler to *always* allocate `MyStruct`-objects `struct MyStruct`. It instructs the compiler to *always* allocate `MyStruct`-objects
on the heap. This way the reference to `s` remains valid even after `g()` returns. on the heap. This way the reference to `s` remains valid even after `g()` returns.
The compiler takes into consideration that `MyStruct` objects are always heap The compiler takes into consideration that `MyStruct` objects are always heap