Skip to content

Commit 1ec96e5

Browse files
authored
Merge pull request #2006 from xushiwei/q
mini spec: size and alignment guarantees
2 parents cd02745 + ef616bf commit 1ec96e5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/spec-mini.md

+22
Original file line numberDiff line numberDiff line change
@@ -1984,4 +1984,26 @@ The function `StringData` returns a pointer to the underlying bytes of the `str`
19841984

19851985
### Size and alignment guarantees
19861986

1987+
For the [numeric types](#numeric-types), the following sizes are guaranteed:
1988+
1989+
```go
1990+
type size in bytes
1991+
1992+
byte, uint8, int8 1
1993+
uint16, int16 2
1994+
uint32, int32, float32 4
1995+
uint64, int64, float64, complex64 8
1996+
complex128 16
1997+
```
1998+
1999+
The following minimal alignment properties are guaranteed:
2000+
2001+
* For a variable `x` of any type: `unsafe.Alignof(x)` is at least 1.
2002+
* For a variable `x` of struct type: `unsafe.Alignof(x)` is the largest of all the values `unsafe.Alignof(x.f)` for each field `f` of `x`, but at least 1.
2003+
* For a variable `x` of array type: `unsafe.Alignof(x)` is the same as the alignment of a variable of the array's element type.
2004+
2005+
A struct or array type has size zero if it contains no fields (or elements, respectively) that have a size greater than zero. Two distinct zero-size variables may have the same address in memory.
2006+
2007+
## Appendix
2008+
19872009
TODO

0 commit comments

Comments
 (0)