[Courses] How's it going?

Xp0nential Xp0nential Xp0nential at root-core.com
Fri Feb 1 23:34:04 EST 2002


Hey

 according to the ANSI C standard:
"
An lvalue of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to its first element; the type of the resultant pointer is pointer-to-T.

(The exceptions are when the array is the operand of a sizeof or & operator, or is a string literal initializer for a character array.)"

Thus saying that A is a pointer is an oversimplification of that ANSI C definition.

thus sizeof is one of these exceptions....


you see in simpler language this whole thing means.

when you define an array as A[3]; for example, you're not defining a pointer...... because in absolute this definition means only that A is the name of block of memory that will be allocated.

saying that the name of the array decays to a pointer to its first elements in most operations .. means when the name of the array is passed to a function , at compile time the compiler when it sees A actually passes &A[0]to that function . Its like saying ok they are asking for array A, whats the address of the first element of array A. its &a[0]; lets pass that. Because once you pass the address of the first element its easier to go to the next element.. etc.. by pointer arithmetic....   
now there are three exceptions where at compile time, the compiler actually when it sees A doesn't pass &A[0]. One of these exceptions being the sizeof() operator which gives you how many elements are in a array.   
thus A[3];   sizeof(A) should give you 3.

thus the name of the pointer by definition is not a pointer to its first element, it only decays to that at compile time when the compiler passes &A[0] to functions when it sees A , except for cases like sizeof.

I hope I was able to explain clearly.
Regards,
xp0nential

--- "Raven, corporate courtesan" <raven at oneeyedcrow.net> wrote:
>Heya --
>
>Quoth Xp0nential Xp0nential (Tue, Jan 29, 2002 at 08:13:06AM -0800):
>> contrary to the popular belief that the name of an array is always a pointer to its first element.
>
>	I don't think we have arrays or pointers yet, but I'll save the
>mail for when we do.
> 
>> the true statement is the name of the array "decays" to a pointer of its first element except in 3 cases: 
>> one of them being the sizeof operator 
> 
>	Decays?  What's that?  And what are the other two cases?  (Not
>that it will make any sense until we have arrays and pointers, but it's
>good to know.)
>
>Cheers,
>Raven
> 
>"I'm not good at running.  But I can yell really loudly.  That works too."
>  -- Paul, on pursuit
>_______________________________________________
>Courses mailing list
>Courses at linuxchix.org
>http://mailman.linuxchix.org/mailman/listinfo/courses

_____________________________________________________________
[Root-Core Network] - [www.root-core.org] - Free E-mail



More information about the Courses mailing list