Correction, a[33]
Chris Torek
chris at mimsy.UUCP
Fri May 26 21:21:00 AEST 1989
In article <5819 at microsoft.UUCP> t-iaind at microsoft.UUCP (Iain Davidson) writes:
>char a[33]
>
>is not an array of 33*sizeof (int)
This much is true (it is size 33*sizeof(char), or 33) ...
>but really 34 slots !!!!!
>
>Remember C is start base 0 not 1.
>
>0..33 = 34 slots of int's.
>
>char a[9] holds 10 characters !!!!
C is not BASIC. `char a[9]' holds nine characters, numbered a[0]
through a[8] inclusive. (Actually, BASICs tend not to be consistent
about allowing a[0].)
And people wonder why microsoft's compilers are buggy :-)
Actually, there is a grain of truth in all this. Given an array
declaration
type-name array-name '[' integral-constant-expression ']' ';'
or
T a[N];
the address &a[N] must be computable. This sometimes means that
array objects need an extra byte---so that
int b[K];
actually sets aside K*sizeof(int)+1 bytes, rather than just K*sizeof(int).
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list