Jacques de Hooge
Jacques de Hooge

Reputation: 7000

Limit to size of array type, while there's not yet an instance

I have the following minimal test program:

struct Test { 
    double contents [1000000000];
};

int main () {
    return 0;
}

It refuses to compile, even though the compiler cannot know wether I will instantiate Test statically, on the stack or on the heap. Why does the compiler complain? Are objects on the heap also restricted to 2GB?

Compilation error report: test.cpp(2): error C2148: total size of array must not exceed 0x7fffffff bytes

Platform: Windows 10 64 bit, 16GB RAM

Compiler: Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27027.1 for x64 Copyright (C) Microsoft Corporation. All rights reserved.

Upvotes: 0

Views: 268

Answers (1)

catnip
catnip

Reputation: 25408

This appears to be a limitation of MSVC. I tried compiling your code with both the 32 bit (x86) and 64 bit (x64) compilers and got the same result (tested with compiler version 19.13.26132, MSVC 2017).

Upvotes: 1

Related Questions