
Andreas Klein wrote:
I have found a strange limitation for the size of an array. The error is the same both for boost 1.36 and for the array in gcc 4.3.2 (and in the gcc 4.4 snapshot I use). I am almost sure that it is a bug of gcc and not of the array implementation.
Here is the code.
#include<array> using namespace std;
int main () { array<unsigned int, (1<<22)> a; // Create a big array
a[(1<<22)-13]=0; // This give a segmantation fault }
In contrast a C-array works fine.
int main () { unsigned int a[1<<22];
a[(1<<22)-13]=0; }
Since the naturale implementation of the array class is just a wrapper around the C-style array this is very strange.
I tryed to track down the bug. You use the following implementation:
template<typename T, unsigned int n> class array { T C[n];
public: typedef unsigned int size_type; T& operator[](size_type p) { return C[p]; } };
I have no clue. But what does GCC do when you try the following? struct big_array { unsigned int C[1<<22]; unsigned int& operator[](unsigned p) { return C[p]; } }; int main () { big_array a; a[(1<<22)-13]=0; // ??? } Kind regards, -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center