Ihor Bondartcov
Ihor Bondartcov

Reputation: 174

What is IntegerType?

I saw golang core and found this:

func make(t Type, size ...IntegerType) Type

What mean IntegerType and Type? It can be C+?

Upvotes: 1

Views: 610

Answers (2)

icza
icza

Reputation: 417662

Your function declaration is from the builtin package, builtin.make()

func make(t Type, size ...IntegerType) Type

That IntegerType links to: builtin.IntegerType:

IntegerType is here for the purposes of documentation only. It is a stand-in for any integer type: int, uint, int8 etc.

So it serves a documentation purpose. Since there is no generics in Go, each type that is used in a declaration must be a "real" type (not a type parameter). But most builtin functions are special, they allow values of multiple types (or even type "names") to be passed.

To express / document this, the builtin package uses the IntegerType as a "pseudo" type, a collective type for any integer type.

Similarly, Type links to builtin.Type:

Type is here for the purposes of documentation only. It is a stand-in for any Go type, but represents the same type for any given function invocation.

This is also for documentation purposes. It is also a "pseudo" type that may substitute any types, but Go doesn't support generics to express this using a valid syntax.

Upvotes: 8

saddam
saddam

Reputation: 829

Integer Type :

IntegerType is here for the purposes of documentation only. It is a stand-in for any integer type: int, uint, int8 etc.

Ex : type IntegerType int

Type :

Type is here for the purposes of documentation only. It is a stand-in for any Go type, but represents the same type for any given function invocation.

Ex: type Type int

According to go document

Upvotes: 5

Related Questions