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

0

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.

c++
arrays
windows
visual-c++
size

1 Answer

1

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).

answered on Stack Overflow Jun 9, 2019 by Paul Sanders

User contributions licensed under CC BY-SA 3.0