yohhoyの日記

技術的メモをしていきたい日記

2進数リテラル in 標準C

プログラミング言語Cの次期仕様C2x(C23)では 2進数リテラル(binary literal) が正式仕様となる。そこ今更とか言わない。

// C2x
unsigned x = 0b101010;
unsigned y = 0B11110000;

ノート:2003年時点の (PDF) Rationale for International Standard Programming Languages Cでは下記の通り否定的だったが、C++14で2進数リテラルが導入されたことも影響していそう。

6.4.4.1 Integer constants
A proposal to add binary constants was rejected due to lack of precedent and insufficient utility.

関連URL