Cannot appear in constant expression

In the following C ++ program:

static const int row = (dynamic_cast<int>(log(BHR_LEN*G_PHT_COUNT)/log(2))); static const int pht_bits = ((32*1024)/(G_PHT_COUNT * G_PHT_COUNT * BHR_LEN)); unsigned char tab[pht_bits][1<<row]; 

I get the error message double log (double) cannot be displayed in constant expression . why am i getting this problem since i put an integer forward? How to fix it?

+4
source share
2 answers

For you, which reduce my answer. Say this code does not work:

 #include <stdio.h> double log(double foo) { return 1.0; } static const int row = static_cast<int>(log(4)/log(2)); int main(void) { printf("%d\n", row); return 0; } 

Original (changed from (int) to static_cast, not that it matters)

 static const int row = static_cast<int>(log(BHR_LEN*G_PHT_COUNT)/log(2)); 
+3
source

The constant expression referenced by the compiler is actually the boundary of the tab array. The sizes of statically distributed arrays must be known at compile time, but the row value cannot be determined until run time, because it is evaluated using a function.

+4
source

All Articles