#confused about : expected type '*main.GUID', found '*const main.GUID'

1 messages · Page 1 of 1 (latest)

peak pollen
#

my function takes in two structs as arguments, both pointers. in my test, i declare two structs and then attempt to take the pointers and pass them into the function. the result is the error above.

this is probably pretty basic, but i've never seen const as part of a type (coming from Go, mostly)

dense plaza
#

the const is applying to the pointer, a const pointer cant coerce to a mutable pointer so you have to change a const to var somewhere.

#

only because taking the address of a const gives you a *const T, while the address of a var gives *T

#

is it too much code to post? you can use something like zigbin.io

peak pollen
dense plaza
#

in this situation i would change compareGUIDs's signature to fn compareGUIDs(right: GUID, left: GUID) bool, since you don't have to mutate them to compare them (you'd also need to change it so you dont pass by address on line 33)

#

taking by const is always preferrable since mutable things can coerce to immutable things, but not the other way around

#

if you did need to mutate them, changing const first and const second to var first and var second would fix it

peak pollen
#

no no need to mutate

#

thanks!

dense plaza
#

np zeroLike

peak pollen
#

hmm now i get this main.zig:73:24: error: parameter of type 'main.GUID' not allowed in function with calling convention 'C'

dense plaza
#

yea, do you need to have compareGUIDs as export? like are you exposing it to a static/dynamic library? if you do you have to make GUID an extern struct

peak pollen
#

oh no i don't

#

that should be pub

#

ok cool now we're in business