Why can't this statement be compiled?


int Century[100][365][24][60][60];

Despite my memory being larger than 2 GB?

It will fail because that is an attempt to create an object on the stack, and your stack is not 2 GB in size. We call this "Stack overflow"; http://en.wikipedia.org/wiki/Stack_overflow

Last edited on
Whats a stack?
It's a section of memory. Follow that link, follow the links in that link. Read about memory.
But I get the error while compiling not while running!
What is the error then?
Last edited on
Your compiler has limits also. It has to work out in advance where things will go in memory and all that sort of thing. Clearly your compiler is unable to deal with an array of this size.

If you must have an array of this size, I suggest that you firstly think of a better way to do it, and secondly don't use arrays but start using C++ containers.
It says: error C2148: total size of array must not exceed 0x7fffffff bytes

What does this number 0x7fffffff physically mean?(I know its a hex number and its value)

I use VS 2010 Pro
That is 2,147,483,647 bytes, which is the largest value a 32-bit signed long can represent. It is just one under 2^31 (or one under (2^32)/2). Recall a byte is generally 8 bits and is the smallest that C++ can deal with, char is a byte, short is two bytes, int is generally but not always 4 bytes, long is 4 bytes, long long is 8 bytes, float is 4 bytes, double is 8 bytes, and sometimes long double is better than double but for some compilers they are the same.

If you array exceeds the maximum number of bytes then you're out of luck.
Last edited on
Its (2^31)-1.

That's the largest signed integer value your system can handle, and it needs those integers to handle memory. You're coming up against the limits of your system.


You're probably trying to compile this in 32-bit mode, so declaring an array this large can't possibly be done.
It should work when compiling for a 64-bit target.
@SameerThigale if you don't even know what a stack is, I suggest reading some c++ books to get down the basics about c++ programming.
Just for the problem: do you intend to count something within a century, each second separately?
If you do that [365] is wrong.
@morus: NO

@buffbill: What?
I think buffbill is talking about leap years, which means you wouldn't have exactly 365 days per year. What is this for anyway? It seems really useless.
@firedraco: Yeah!
Works on my 64 bit system. I even assigned values into it at runtime.
Topic archived. No new replies allowed.