From d5f5620aea4063af9a51a07c6ca541a5653acc73 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Mon, 21 Oct 2024 13:49:43 +0800 Subject: [PATCH] mini spec: zero value --- doc/spec-mini.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/spec-mini.md b/doc/spec-mini.md index 071c8a197..a1cb14d6b 100644 --- a/doc/spec-mini.md +++ b/doc/spec-mini.md @@ -1773,3 +1773,22 @@ Here is a complete Go+ package that implements XXX. ```go TODO ``` + +## Program initialization and execution + +### The zero value + +When storage is allocated for a [variable](#variables), either through a declaration or a call of `new`, or when a new value is created, either through a composite literal or a call of `make`, and no explicit initialization is provided, the variable or value is given a default value. Each element of such a variable or value is set to the _zero_ value for its type: `false` for booleans, `0` for numeric types, `""` for strings, and `nil` for pointers, functions, interfaces, slices, and maps. This initialization is done recursively, so for instance each element of an array of structs will have its fields zeroed if no value is specified. + +These two simple declarations are equivalent: + +```go +var i int +var i int = 0 +``` + +TODO + +### Package initialization + +TODO