A leading zero changes a Go integer literal to base 8, so 010 means decimal 8 rather than decimal 10. Consequently, 100 + 010 prints 108, a common reading mistake when existing code is treated as decimal. section 3.1
Choose the notation according to whether readability or compatibility with existing code matters:
- Prefer 0o644 for an explicit octal value; the prefix makes the base immediately visible. section 3.1
- Use 0644 when matching conventional Linux permission notation, but recognize that the leading zero still means base 8. section 3.1
- Avoid 0O644 when possible because uppercase O can resemble zero in some fonts. section 3.1
File permissions
Pass an octal literal when opening a file with Linux-style permissions: os.OpenFile("foo", os.O_RDONLY, 0644). For clearer base identification, write the same permission as os.OpenFile("foo", os.O_RDONLY, 0o644). section 3.1
sum := 100 + 010 fmt.Println(sum)
Inspect the minimal expression that exposes the decimal-versus-octal misconception. section 3.1
