g++ version: 4.1.1 target platform: linux kernel 2.6.13-15 with option "pedantic" the following line does not compile outside main:
int array3[(const unsigned short) (20.5 * 3)]; error message from compiler is: "error: array bound is not an integer constant" to me this is wrong because the expression "(const unsigned short) (20.5 * 3)" is an integer constant Note: within main the same expression does compile with pedantic option Here is a sample program: // Begin of sample program // // Question: Why does array3 not compile ? // this file demonstrates a problem in compilation with the pedantic option // // btspc21 > g++ -pedantic -c compiler_fail.cc // compiler_fail.cc:18: error: array bound is not an integer constant // float conversion alone compiles int array1[(const unsigned short) (20.5)]; // calculation compiles int array2[(const unsigned short) (20 * 45)]; // combination does not compile int array3[(const unsigned short) (20.5 * 3)]; int main() { // combination in main does compile int array4[(unsigned short) (20.5*3)]; } // End of sample program -- Summary: g++ -pedantic issues error array bound not integer although it is a constant Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: brase at lucent dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28981