GCCとG++でのswitch文内のcaseラベルにおけるconst定数の扱いの違い
GCCとG++でのswitch文内のcaseラベルにおけるconst定数の扱いの違い
#include <stdio.h> int main(void) { const int A = 2; int a = 2; switch(a) { case A: puts("ok"); break; } }
$ gcc test.c test.c: In function ‘main’: test.c:10: error: case ラベルを整数定数に還元できません $ cp test.c test.cpp $ g++ test.cpp
C(GCC)ではconst定数は使えない・・・
#defineで代用するべきのようだ。
C++(g++)では問題無し。
他のコンパイラでは試してない。