diff --git a/Golang/Golang Document.md b/Golang/Golang Document.md index 4b7a81c..661db2e 100644 --- a/Golang/Golang Document.md +++ b/Golang/Golang Document.md @@ -310,3 +310,67 @@ ok git.kazusa.red/asahi/fuzz-demo 10.360s > #### new interesting > `new interesting`指会扩充code coverage的用例输入,在fuzz test刚开始时,new interesting数量通常会因发现新的代码路径快速增加,然后,会随着时间的推移逐渐减少 +## syntax +### iota +`iota`关键字代表连续的整数变量,`0, 1, 2`,每当`const`关键字出现时,其重置为0 + +其使用示例如下 +```go +package main + +import "fmt" + +const ( + ZERO = iota + ONE +) + +const TWO = iota + +const ( + THREE = iota + FOUR +) + +func main() { + fmt.Println(ZERO) // 0 + fmt.Println(ONE) // 1 + fmt.Println(TWO) // 0 + fmt.Println(THREE) // 0 + fmt.Println(FOUR) // 1 +} +``` + +另外,const关键字也支持如下语法: +```go +package main + +import ( + "fmt" + "reflect" +) + +type Shiro uint8 + +const ( + ZERO Shiro = iota + ONE +) + +const TWO Shiro = iota + +const ( + THREE Shiro = iota + FOUR +) + +func main() { + fmt.Printf("ZERO %d, %s\n", ZERO, reflect.TypeOf(ZERO).Name()) + fmt.Printf("ONE %d, %s\n", ONE, reflect.TypeOf(ONE).Name()) + fmt.Printf("TWO %d, %s\n", TWO, reflect.TypeOf(TWO).Name()) + fmt.Printf("THREE %d, %s\n", THREE, reflect.TypeOf(THREE).Name()) + fmt.Printf("FOUR %d, %s\n", FOUR, reflect.TypeOf(FOUR).Name()) +} +``` +当const在`()`中声明多个常量时,如首个常量的类型被指定,则后续常量类型可省略,后续类型与首个被指定的类型保持一致。 +