CBFalconer said:
Wojtek said:
long array[SIZE_MAX];
I maintain that, whenever (sizeof (long) > 1), that is a compile
error.
We know that you do, but we don't believe that you have
demonstrated that to be true.
I have quoted the appropriate portion of the standard. Any other
interpretation involves a contradiction.
My interpretation of the relevant words implies that a conforming
implementation of C can
1. reject any declaration that refers to a type bigger than
SIZE_MAX, as
exceeding an implementation limit.
That's definitely true. It is also allowed to set both SIZE_MAX and
the maximum size of an object to 65536. However, the standard allows
these two limitations separately: SIZE_MAX in 7.18.3.2, regarding
<stdint.h>, and object size in 5.2.4.1, Translation limits. I has not
been proven, by Chuck or anyone else, that these two values are
related or must be the same. From the lack of any relationship between
those two values - other than that must both be at least 65536 -
mentioned in the standard, the conclusion can be drawn that there
indeed is not any such relationship. As a matter of fact, the maximum
object size may be less than 65536 in a freestanding implementation,
but no such exception exists for SIZE_MAX.
SIZE_MAX is simply the largest possible value to be contained in an
object of type size_t. I suggest that objects such as
int ia[65536];
char ca[250000];
are valid even when size_t is a short (SIZE_MAX = 65536). The result
of sizeof ia or sizeof ca, in such a case is ID, same as in
int i = 100000;
short s = (short) i;
according to 6.3.1.3.3, or whatever the standard says in 6.3.1.3.2
(Can someone please that to me?)
2. have calloc(nmemb, size) return a non-null pointer to enough
memory
to store an array nmemb objects of the specified size, even if
nmemb*size has a mathematical value that is greater than
SIZE_MAX. It
will return sufficient memory for the specified number of objects of the
specified size, even though the amount of memory required is
greater
than the value of nmemb*size, interpreted as a C expression
rather than
a mathematical one.
And memory returned is addressable by array subscrilpt, which is not
necessarily of type size_t, for two resons. One I mentioned above,
the other is that size_t is (or may be) an unsigned integral type,
while an array subscript is required to be of any integer type,
including a negative long long (6.5.2.1.1, by exclusion of any other
constraints).
-- Marty Amandil
I hope I didn't make