Subject: Re: pointers &arrays[]
From: [email-masked] (Jason Zions)

24 Nov 1997 05:45:34 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: Scott Warner <[email-masked]>
Cc: [email-masked]

> array == &array[0]
> array == &array
> *array == array[0]
> *(array+n) == array[n]
> 
> are all true given array[n].  In this case, sizeof(array) returns the size
> of the entire array, not array[0].  Are there other examples where this
> pointer notation fails?
> Lastly, is this pointer notation implementation dependent or is it part of
> the de facto standard?

I don't know about de facto standards for C; nowadays, there pretty much
aren't any, since there is a de jure standard, ISO C (IS 9981 if memory
serves). And the pointer/array equivalences you mentioned are required
by the standard.

The compiler can only make sizeof(array) equal to the size of the array
when in fact the compiler can see a complete definition of the array
in-scope. If you pass array as a parameter to a function, a sizeof()
expression in that function generally won't know how big the array
actually is.

Arrays are not first-class datatypes in C; most of the time an array of
type Foo has to be treated as a pointer to an element of type Foo.

Jason
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".