KDOC 450: Goで型のメモリ上のサイズの仕様がどうなっているか見る

この文書のステータス

  • 作成
    • 2025-10-17 貴島
  • レビュー
    • <署名>

概要

同じ型であっても、ビルド対象となるCPUアーキテクチャによってメモリサイズ変動する型がある。Goではどうなっているだろうか。仕様を見る。

サイズが実装依存の型。

There is also a set of predeclared integer types with implementation-specific sizes: uint either 32 or 64 bits int same size as uint uintptr an unsigned integer large enough to store the uninterpreted bits of a pointer value

The Go Programming Language Specification - The Go Programming Language

サイズが固定の型。

An integer, floating-point, or complex type represents the set of integer, floating-point, or complex values, respectively. They are collectively called numeric types. The predeclared architecture-independent numeric types are:

uint8 the set of all unsigned 8-bit integers (0 to 255) uint16 the set of all unsigned 16-bit integers (0 to 65535) uint32 the set of all unsigned 32-bit integers (0 to 4294967295) uint64 the set of all unsigned 64-bit integers (0 to 18446744073709551615) (略…)

The Go Programming Language Specification - The Go Programming Language

関連

Backlinks