【源码阅读】【苦练基本功】Golang内置函数分析
Golang package builtin
中内置函数我分为两部分介绍,第一部分为基础类型,第二部分为包含函数、接口,较复杂一些
第一部分
// bool is the set of boolean values, true and false.
type bool bool// true and false are the two untyped boolean values.
const (true = 0 == 0 // Untyped bool.false = 0 != 0 // Untyped bool.
)// uint8 is the set of all unsigned 8-bit integers.
// Range: 0 through 255.
type uint8 uint8// uint16 is the set of all unsigned 16-bit integers.
// Range: 0 through 65535.
type uint16 uint16// uint32 is the set of all unsigned 32-bit integers.
// Range: 0 through 4294967295.
type uint32 uint32// uint64 is the set of all unsigned 64-bit integers.
// Range: 0 through 18446744073709551615.
type uint64 uint64// int8 is the set of all signed 8-bit integers.
// Range: -128 through 127.
type int8 int8// int16 is the set of all signed 16-bit integers.
// Range: -32768 through 32767.
type int16 int16// int32 is the set of all signed 32-bit integers.
// Range: -2147483648 through 2147483647.
type int32 int32// int64 is the set of all signed 64-bit integers.
// Range: -9223372036854775808 through 9223372036854775807.
type int64 int64// float32 is the set of all IEEE-754 32-bit floating-point numbers.
type float32 float32// float64 is the set of all IEEE-754 64-bit floating-point numbers.
type float64 float64// complex64 is the set of all complex numbers with float32 real and
// imaginary parts.
type complex64 complex64// complex128 is the set of all complex numbers with float64 real and
// imaginary parts.
type complex128 complex128// string is the set of all strings of 8-bit bytes, conventionally but not
// necessarily representing UTF-8-encoded text. A string may be empty, but
// not nil. Values of string type are immutable.
type string string// int is a signed integer type that is at least 32 bits in size. It is a
// distinct type, however, and not an alias for, say, int32.
type int int// uint is an unsigned integer type that is at least 32 bits in size. It is a
// distinct type, however, and not an alias for, say, uint32.
type uint uint// uintptr is an integer type that is large enough to hold the bit pattern of
// any pointer.
type uintptr uintptr// 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.
type byte = uint8// 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.
type rune = int32
主要注意几个点:
type int int
大小至少32位也就是至少4字节,为什么说是至少呢?因为int类型所占字节数跟操作系统有关,如果是32位就是4个字节,如果是64位就是8个字节,type int int
和type int32 int32
不同,int32永远是32位,int64永远是64位。type string string
string可能是空,但不能为nil,这一点和Java不同,Java中String可以为null。string是不可变的,这一点和Java相同。type uintptr uintptr
是一个integer类型,空间足够大可存储任何指针。byte
和uint8
类型是相同的,可以说是uint8
的别称,byte
更简单一些。rune
和int32
类型是相同的,rune
更简单一些。
第二部分
any
// any is an alias for interface{} and is equivalent to interface{} in all ways.
type any = interface{}
any
和interface{}
是相同的,不要以为是泛型关键词,为了少写一些字母所以会用any
,下面举了一个例子
func convert(t any){switch t.(type){case int://case string://case bool://}}func main() {f(2)f(true)f("煎鱼好!")}
comparable
// comparable is an interface that is implemented by all comparable types
// (booleans, numbers, strings, pointers, channels, arrays of comparable types,
// structs whose fields are all comparable types).
// The comparable interface may only be used as a type parameter constraint,
// not as the type of a variable.
type comparable interface{ comparable }
comparable
是由所有可比较类型(包括booleans, numbers, strings, pointers, channels,interface, arrays中元素为可比较类型,
以及structs 中所有属性都是可比较类型)实现的接口。只能用于类型参数约束,不用于变量类型比较,举个
【源码阅读】【苦练基本功】Golang内置函数分析相关推荐
- Golang 内置函数
Golang中内置了一些函数,在使用这些函数时,不必以包名为前缀来调用,而是直接写函数名即可调用,这些函数都是一些基础的函数,在程序设计中应用比较普遍,所以一定要牢记这些最基本的函数用法.下边来介绍一 ...
- golang内置函数
Go 语言拥有一些不需要进行导入操作就可以使用的内置函数.它们有时可以针对不同的类型进行操作,例如:len.cap 和 append,或必须用于系统级的操作,例如:panic.因此,它们需要直接获得编 ...
- 多城市教育培训机构行业企业站群系统源码-强大的SEO功能-内置三千多个城市
简介: 多城市教育培训机构行业企业站群系统源码,强大的SEO功能,内置三千多个城市. 重点说明: 仅限win服务器安装使用,Linux系统安装站点后台存在一些问题 强大SEO功能,城市分站自主选择,数 ...
- [PHP源码阅读]trim、rtrim、ltrim函数
trim系列函数是用于去除字符串中首尾的空格或其他字符.ltrim函数只去除掉字符串首部的字符,rtrim函数只去除字符串尾部的字符. 我在github有对PHP源码更详细的注解.感兴趣的可以围观一下 ...
- trim函数 php,[PHP源码阅读]trim、rtrim、ltrim函数
trim系列函数是用于去除字符串中首尾的空格或其他字符.ltrim函数只去除掉字符串首部的字符,rtrim函数只去除字符串尾部的字符. 我在github有对PHP源码更详细的注解.感兴趣的可以围观一下 ...
- PHP yii 框架源码阅读(二) - 整体执行流程分析
转载链接:http://tech.ddvip.com/2013-11/1384432766205970.html 一 程序入口 <?php// change the following pat ...
- 【蓝牙sbc协议】sbc源码阅读笔记(四)——sbc_encode函数详解
sbc_encode函数详解 函数定义: // sbc.c SBC_EXPORT ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t in ...
- map内置函数分析所得到的思路
map:会根据提供的函数对指定序列做映射. map(func, *iterables) --> map objectMake an iterator that computes the func ...
- php内置函数分析之strtoupper()、strtolower()
strtoupper(): 1 PHP_FUNCTION(strtoupper)2 {3 zend_string *str;4 5 ZEND_PARSE_PARAMETERS_START(1, 1)6 ...
最新文章
- 昨天在公司加班,上午好像就是弄一个ftp的linux服务问题
- python 删除第三方库_python 安装移动复制第三方库操作
- Leetcode: Single Number
- ARGB和PARGB
- mysql的优化-添加环境变量启动服务
- 查看函数说明_Axure函数使用说明
- 用jsp开发web应用并不是一个高效率的选择
- 使用threeJS根据点的坐标绘制曲线
- 给职场人士的四点良心建议
- css盒模型与层模型与定位
- Apple Silicon配置二进制环境(一)
- python经纬度转换xy坐标公式_经纬度坐标转换为距离及角度(Python)
- 校园火灾项目结合Focus
- android 内存分析工具ASAN 学习
- Open3d读写pcd点云文件
- 完数(难度系数:半颗星)
- 面向单片机编程(三)- 数码管显示
- 是终点也是起点:你的恋爱目标是什么?
- 计算机系统在英语中的运用,在应用系统中探究计算机屏幕英语句法规律.doc
- 山东大学软件学院2022年数据库课程设计环境配置教程