Go equivalent of a void pointer in C

According to the Go Programming Language Specification:

A type implements any interface comprising any subset of its methods and may therefore implement several distinct interfaces. For instance, all types implement the empty interface:

interface{}

If you search within that document for interface{}, you’ll see quite a few examples of how you can use it to do what you want.


Update (2023-09-27): Starting in Go 1.18 (March 2022), Go provides the builtin alias any. Per its documentation:

type any = interface{}

any is an alias for interface{} and is equivalent to interface{} in all ways.

This addition was related to the addition of support for generics, also in Go 1.18, which slightly reconceptualized how interfaces work (though in a completely compatible way). Here’s the current spec language:

Every type that is a member of the type set of an interface implements that interface. Any given type may implement several distinct interfaces. For instance, all types implement the empty interface which stands for the set of all (non-interface) types:

interface{}

For convenience, the predeclared type any is an alias for the empty interface.

Leave a Comment