Skip to content

Function Address

IsaacShelton edited this page Mar 21, 2022 · 1 revision

func &

The func & operator is used for obtaining the memory address of a function.

Name-based match

If arguments are not specified, then the first function defined with the given name will be matched. A warning will be issued if other functions with the same name exist.

func &sum

Argument-based match

If arguments are specified, then the specific function with "matching" argument types will be given.

func &sum(int, int)

Usage Example

import basics

func main {
    my_function_pointer func(int, int) int = func &sum
    printf("8 + 13 = %d\n", my_function_pointer(8, 13))
}

func sum(a, b int) int {
    return a + b
}
Clone this wiki locally