What is IntegerType?

  • A+
Category:Languages

I saw golang core and found this:

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

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

 


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.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: