Standard library / runtime

runtime.Callers()

Collects return program counters into a caller-provided slice. Use CallersFrames for symbolic interpretation and inlining. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Callers(skip int, pc []uintptr) int

Parameters & Attributes

NameTypeDescription
skipintNumber of frames to skip; zero starts at Callers itself.
pc[]uintptrDestination slice for return program counters.

Return Value

int

Number of initialized entries in pc.

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime")
func main() {  pcs := make([]uintptr, 16)  n := runtime.Callers(0, pcs)  fmt.Println(n > 0 && n <= len(pcs))}
Go Reference