-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed array getting wrong address #20378
Comments
fn main() {
mut buffer := [u8(56), 55]
mut buffer2 := [u8(56), 55]
mut fixed_buffer := [u8(56), 55]!
mut fixed_buffer2 := [u8(56), 55]!
mut str := &u8(0)
unsafe { str = &u8(&buffer) }
println('${str: p}, buffer.data: ${buffer.data}')
unsafe { str = &u8(&buffer2) }
println('${str: p}, buffer2.data: ${buffer2.data}')
unsafe { str = &u8(&fixed_buffer) }
println('${str: p}, fixed_buffer[0]: ${&fixed_buffer[0]: p}')
unsafe { str = &u8(&fixed_buffer2) }
println('${str: p}, fixed_buffer2[0]: ${&fixed_buffer2[0]: p}')
} The address is indeed random. the address of the array is actually the address of struct array, and the address of element [0] is buffer.data Fixed arrays, have the same address as the element[0] because array is a struct, and fixed arrays are not
|
After a discussion in the discord chat, long after the linked one, just for anybody who will fall onto this issue again, the conclusion is this: println(&str) essentially prints the first element. Now, why is this done?
As a user of the language but also someone who also likes to sympathize with the devs, I get both sides. From user's perspectiveI get it's annoying to think why they would both behave the same. They're both arrays in the eyes of the user. So, it's admittedly unexpected from a user to see these kind of results. From the language's programmers' perspectiveWhen one is a Ideally, from my personal perspective, both would have to behave the same. But the programming behind would or will have to be redesigned around that issue. |
Describe the bug
fixed array getting wrong address
Reproduction Steps
Expected Behavior
Current Behavior
Possible Solution
No response
Additional Information/Context
No response
V version
latest
Environment details (OS name and version, etc.)
Ubuntu
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: