美文网首页
0-数据类型

0-数据类型

作者: 浩玥当空 | 来源:发表于2019-05-18 19:54 被阅读0次

1、通过type定义的类型,与原类型不同。

2、计算架构相关的整数类型

int,uint

3、显式表达自身宽度的整数类型

int8,int16,int32,int64
uint8,uint16,uint32,uint64

4、浮点数

浮点数类型有两个:float32/float64

5、复数类型

复数类型有两个:complex64/complex128

6、byte与rune

type byte = uint8

//byte is an alias for uint8 and is equivalent to uint8 in all ways.
//It is used, by convention, to distinguish byte values from 8-bit unsigned integer values.

byte是uint8的别名,两者完全等价。定义byte,只是因为按照惯例,使对字节值和8位无符号整数值进行区分。

type rune = int32

rune is an alias for int32 and is equivalent to int32 in all ways. It is used, by convention, to distinguish character values from integer values.

rune是int32的别名,两者完全等价。定义rune,只是因为按照惯例,将字符值与整数值进行区分。

gofrontend\go\gogo.cc

// "byte" is an alias for "uint8".
  uint8_type->integer_type()->set_is_byte();
  Named_object* byte_type = Named_object::make_type("byte", NULL, uint8_type,
                loc);
  byte_type->type_value()->set_is_alias();
  this->add_named_type(byte_type->type_value());

// "rune" is an alias for "int32".
  int32_type->integer_type()->set_is_rune();
  Named_object* rune_type = Named_object::make_type("rune", NULL, int32_type,
                loc);
  rune_type->type_value()->set_is_alias();
  this->add_named_type(rune_type->type_value());

7、unsafe.Pointer、uintptr

src\builtin\builtin.go

// uintptr is an integer type that is large enough to hold the bit pattern of

// any pointer.

type uintptr uintptr
src\unsafe\unsafe.go

type ArbitraryType int

type Pointer *ArbitraryType

//- A pointer value of any type can be converted to a Pointer.
//- A Pointer can be converted to a pointer value of any type.
//- A uintptr can be converted to a Pointer.
//- A Pointer can be converted to a uintptr.

两组可以相互转转换类型
1、Pointer、任意指针类型
2、Pointer、uintptr

8、别名

src\builtin\builtin.go

type IntegerType int

type Type int

type FloatType float32

type ComplexType complex64

9、字符串

字符串的表示法有两种:原生表示法和解释型表示法。

原生表示法:反引号"`"包裹字符序列。不会对/t等做转义。

解释型表示法:双引号"""包裹字符序列。

字符串值是不可变。因为字符串底层是一个指针,可能指向一个常量。

10、字典类型

map[K]T

字典的键类型必须是可比较的

11、通道类型

chan T

与其他的数据类型不同,我们无法表示一个通道类型的值,因此,我们无法用字面量来为通道类型的变量赋值。只能通过调用内建函数make来达到目的。

操作符<-向通道值发送数据.

value, ok := <- ch1

ok的值是bool类型的,代表通道值的状态。

true:通道值有效

false:通道值已无效(或称已关闭)

对通道值的重复关闭会引发运行时异常,会使程序崩溃。

默认情况下,通道都是双向的,即双向通信。

接收通道:type Receiver <- chan int

发送通道:type Sender char <- int

相关文章

  • 0-数据类型

    1、通过type定义的类型,与原类型不同。 2、计算架构相关的整数类型 3、显式表达自身宽度的整数类型 4、浮点数...

  • sql sever 数值类型

    ·0-

  • 白酒里加点它,人参虎鞭都比不了!连喝3天,身体猛如 牛!

    【】o[]\]\=、;'\'[]\'\【=0-=0================================...

  • H

    从0->1的过程 是幸福的。

  • 173. 链表插入排序

    用插入排序对链表排序样例Given 1->3->2->0->null, return 0->1->2->3->nu...

  • 0-开始

    雨,淅沥淅沥。 又一年的春雨。下啊下啊,沿着伞沿。眼前的雨帘,那样沉重,北方,冷气呼啸而来。 室内倒是肃静的异常,...

  • 0-大纲

    Time: 20200129 Introduction Getting Started Three Core Co...

  • 0-楔子

    在很多人眼中,地球就是一颗生养我们的星球,再上升一层来讲,地球就是太阳系中唯一一颗适合人类居住的星球。但是,...

  • 0-简介

    了解 1 .常见的网站今年好像都加了这个东西。腾讯,知乎,jd,淘宝。觉得这个技术有意思,感觉可以搞下.而且在一个...

  • 0-序

    本系列故事均为虚构,如有雷同,纯属巧合 周六早晨, 我带孩子去公园玩, 这"熊孩子"像往常一样顽皮, 一边踢着路边...

网友评论

      本文标题:0-数据类型

      本文链接:https://www.haomeiwen.com/subject/hrfxzqtx.html