Adresses of functions

113 views
Skip to first unread message

Luis Furquim

unread,
Sep 30, 2016, 2:39:06 PM9/30/16
to golang-nuts
Hello gophers!

I need to have a list of registered functions. I want to control if a function is already registered and, if so, just ignore any new registration of that function. My idea was to use the function's adress as the key of registered functions. So, to get the address of a function I just do this:
x := fmt.Sprintf("%#v",funcToRegister)
x = x[11:len(x)-1]

My question is: does the function address may change (relocation) over time?

Thank you in advance
Luis Otavio de Colla Furquim

Ian Lance Taylor

unread,
Sep 30, 2016, 3:40:00 PM9/30/16
to Luis Furquim, golang-nuts
On Fri, Sep 30, 2016 at 11:38 AM, Luis Furquim <luisf...@gmail.com> wrote:
>
> I need to have a list of registered functions. I want to control if a
> function is already registered and, if so, just ignore any new registration
> of that function. My idea was to use the function's adress as the key of
> registered functions. So, to get the address of a function I just do this:
> x := fmt.Sprintf("%#v",funcToRegister)
> x = x[11:len(x)-1]
>
> My question is: does the function address may change (relocation) over time?

In the current implementation, the address of a regular top-level
function (not a function closure defined within a function) will not
change while the program is running. However, this is not guaranteed
by the language, and can imagine other implementations in which that
is not true.

Ian

Luis Furquim

unread,
Sep 30, 2016, 4:14:47 PM9/30/16
to Ian Lance Taylor, golang-nuts
Ok, Thank you!
Reply all
Reply to author
Forward
0 new messages