V: what is the address of struct ?

Created on 26 Nov 2020  路  12Comments  路  Source: vlang/v


V version:
OS: win10

What did you do?

struct Mo {mut: x int}

fn main() {

mut w:=Mo{1}

println(&w) //this doesn't work
println(&(w.x)) //this work
}

What did you expect to see?
the address of w

What did you see instead?

Bug

Most helpful comment

Why should V not print addresses? That makes cave man debugging much harder.

You can print voidptr addresses:

println(voidptr(&w)) // 13fe8c

All 12 comments

the second example shows you the address of x. but it shouldn't. We won't print addresses. the first println is correct but a missing & in front.

Hi
I don't understand.
The second println OK, because it print the address of w.x
The first one doesn't print the adress of w.

it should never print the address imo

I know
I think it should print : &{1} //in Go it is the result

but in V : Mo{ x:1 }

Is it OK ?

Why should V not print addresses? That makes cave man debugging much harder.

@medvednikov should decide

Why should V not print addresses? That makes cave man debugging much harder.

You can print voidptr addresses:

println(voidptr(&w)) // 13fe8c

OK. Thank you Sir.

Why should V not print addresses? That makes cave man debugging much harder.

You can print voidptr addresses:

println(voidptr(&w)) // 13fe8c

will this be the official way to print addresses?

There is a builtin ptr_str function, that (afaik) does the same thing but is more explicit:

println(ptr_str(&w)) // 7ffee5210888
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jtkirkpatrick picture jtkirkpatrick  路  3Comments

markgraydev picture markgraydev  路  3Comments

medvednikov picture medvednikov  路  3Comments

penguindark picture penguindark  路  3Comments

XVilka picture XVilka  路  3Comments