hello
example
Vtest = ref object
name : string
let fldx = new(Vtest)
fldx.name = "test"
proc setT( val : string) :string= return val
var x = setT(fldX.name)
Hint: passing 'fldx.name' to a sink parameter introduces an implicit copy; use 'move(fldx.name)' to prevent it [Performance]
var x = setT(move(fldX.name)) not erreur --> oups variable ????
var s = fldX.name
var x = setT(move(s)) not erreur
nim c -f --deadCodeElim:on --gc:arc ....
please can you explain to me or correct
Thank you
Well move can be a dangerous operation so you should use it when you're 100% sure that your code won't use the variable you move'd afterwards. This code will output an empty string because there was a move on fldX.name and it's now empty:
type
Vtest = ref object
name : string
let fldx = new(Vtest)
fldx.name = "test"
proc setT(val: string): string = val
var x = setT(move(fldX.name))
echo fldX.name
You should understand that hints are hints - you shouldn't always blindly follow them.
So I used "move", but actually I lost the value and the variable. moreover we see it in "echo" after.
I wanted to follow the recommendations !!! I finally try normally when I compile a C / C ++ program I make sure that it has no more errors.
that's why I initialized x and put move (x) so as to no longer have an error even if the variable was only useful for passing parameters
var x = fldx.name
proc (.... , move(x) )
that way I could still use "fldx.name"
this is what i did in the program
This hint message needs to be fixed. If blindly using move(x) was sound, the compiler could have done it for you too. What the compiler really means is that you have to do an analysis to see whether the copy can be avoided by a program restructuring.
There is also a blog post by Araq but it may be outdated.
Blog posts are always outdated (maybe I should change that?), the official documentation is up to date.