
Long as array/pointer address
Quote:
> I'd like to do the following:
> long index = 10;;
> char *string = "This is a test string";
> printf("%c\n", string[index]);
> printf("%c\n", *(string + index));
> but when I compile the above in a 16bit compiler (haven't tried it on a
> 32bit compiler), the compiler apparently casts the index to int in the
> two printf lines. Are array/pointer indexes int according to the ANSI
> standard?
The standard allows any integral type. However, the compiler is allowed to
use magic. In many 16 bit implementations objects larger than can be
indexed with a 16 bit integer are not supported or are supported only in
some non-standard way (e.g., far in most PC compilers). If the compiler knows
that the object cannot be large enough to need a long for indexing it may
optimize by converting to int (or, for that matter, to char) when it does
the calculation.
--
Mike Rubenstein