>In article <455d7f20$0$25910$>,
>jacob navia <> wrote (in part):
>>array[integer expression]
...
>>To overcome this,
>>is an implementation allowed to cast array indexes to long long?
(This, of course, is why the "best" type for array indexing is
generally size_t, or a signed variant of size_t: size_t can [and
should] be "unsigned long long" on implementations with memory
sizes exceeding UINT_MAX.)
In article <ejjv93$35q$>
Walter Roberson <> wrote:
>No need for the implementation to cast them.
Moreover, if an implementation does an internal conversion of whatever
integral type is being added to a pointer value, so that:
ptr + i
and:
*(ptr + i) /* aka ptr[i] */
convert the value in "i" to (signed or unsigned) "long long" before
doing the addition, this is still an "internal conversion", *not* a
"cast". A cast is the syntactic construct in which a type-name
enclosed in parentheses is used to force an explicit conversion.
(Note that most implementations do indeed convert "i", if it is
plain, signed, or unsigned char; plain or signed short; or unsigned
short. That is:
unsigned char i;
...
use(ptr[i]);
has the same effect as a version with a cast:
use(ptr[(int)i]);
It is tempting to call internal conversions "implicit casts", but
ever since the original ANSI C standard -- which defined "cast" as
the explicit conversion, and nothing else -- came out, this temptation
should be resisted.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.