Carol said:
Everyone, thank you for your help. I feel a little like I'm asking
Einstein to explain relativity to me. I'm way out of my league.
So, thanks for your patience.
Anyway, I'm still confused about how large a simple int array can be.
I understand what Jack and Ben said about the Standard guaranteeing
at least int a[32767], but I don't understand why I can't have an
array of int a[600000], especially since I have 311MB of unused memory
on my machine, and I thought the machine would allow programs up to
4GB.
Your machine (like many) apparently exceeds the minimum
requirements imposed by the C language Standard. It's sort
of like the Federal definition of the minimum wage: Employers
are required to pay at least thus-and-such much per hour of
labor, but many laborers nonetheless demand and receive more.
Be happy; you're rich!
Here's my little test program, which works for 500000, but fails for
600000.
Your C implementation is giving you more than the minimum,
but does in fact have a limit on how big the array can be.
You're rich, but you're not Bill Gates.
All help to relieve my confusion is appreciated. I think I'm not
understanding something very fundamental.
#include <stdio.h>
//#define NNN 600000
#define NNN 500000
int main() {
long i;
int a[NNN];
Here's another issue. C data objects can have various
"storage classes:" automatic, static, and dynamic. The amount
of memory available for an object can be different for the
different storage classes. Your a[] array occupies automatic
storage, which is typically (although not necessarily) subject
to the tightest space restrictions. You may see dramatically
different results if you change the above to
int main() {
static int a[NNN};
...
or
int main() {
int *a = malloc(NNN * sizeof *a);
if (a != NULL) {
...
The first of these uses static storage for a[], and the
second replaces the array with a pointer to dynamic storage.
There will be limits on how much static or dynamic memory
you can devote to your data, but they're likely to be looser
than the limits on automatic storage.
You're rich, but if you want to augment your wealth it's
better to rob big banks than little ones.