MinGW GNU コンパイラを使用して C++ を作成していますが、外部で定義された整数変数を switch ステートメントのケースとして使用しようとすると、問題が発生します。次のコンパイラ エラーが発生します。
整数変数を extern として定義したので、コンパイルする必要があると思いますが、何が問題なのか知っている人はいますか?
以下に例を示します。
test.cpp
#include <iostream>
#include "x_def.h"
int main()
{
std::cout << "Main Entered" << std::endl;
switch(0)
{
case test_int:
std::cout << "Case X" << std::endl;
break;
default:
std::cout << "Case Default" << std::endl;
break;
}
return 0;
}
x_def.h
extern const int test_int;
x_def.cpp
const int test_int = 0;
このコードは、Visual C++ 2008 で正しくコンパイルされます。さらに、私のモンタナの友人が ISO C++ 標準をチェックしたところ、どの const-integer 式も機能するはずです。これはおそらくコンパイラのバグですか、それとも明らかな何かを見逃していますか?
コンパイラのバージョン情報は次のとおりです。
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs から仕様
を読み取る: ../gcc-3.4.5-20060117-3/configure --with-gcc --with- gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada, objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm -- disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
スレッド モデル: win32
gcc バージョン 3.4.5 (mingw-vista スペシャル r3)