Hmmm. that's interesting. Apparently my memory of 25 years of c coding is in
error. From the FAQ you pointed me to:

 

/*********

A reference to an object 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.

That is, whenever an array appears in an expression, the compiler implicitly
generates a pointer to the array's first element, just as if the programmer
had written &a[0]. 

*********/

This is a truth. In multidimensional arrays, all but the lowest level array
contain pointers to the beginning of the next level.. I wish I was better at
ascii graphics, I could draw this out..

 

The compiler will generate access code that looks something like this for
multidimensional array access:

 

*(*(level1 + n) + n)...

 

Try preprocessing to assembler and check out the resulting code.

 

It is this that I was referring to. It also behooves me to remember that
arrays in c are contiguous blocks of a type. That's all. They really don't
have any more of a special meaning than that. When we are coding in c we are
coding at a lower level that C#, or VB. We need to remember that, or we WILL
get bitten with frustrating special features that creep into our programs.

 

Michael

  _____  

From: [email protected] [mailto:[email protected]] On Behalf Of
Paul Herring
Sent: Monday, May 11, 2009 10:57 PM
To: [email protected]
Subject: Re: [c-prog] Difference b/w pointer to pointer and 2D arrays

 






On Tue, May 12, 2009 at 3:06 AM, Michael Comperchio <mcmp...@gmail.
<mailto:mcmprch%40gmail.com> com> wrote:

> A two dimensional array of characters..
> int myarray[10][10];
>
> the first dimension is an array of 10 pointers, each pointing to the
> beginning of an array of 10 integers.

Um, no it's not. It may sometimes act like it, but there are no pointers
there.

You may find http://c-faq. <http://c-faq.com/aryptr/aryptr2.html>
com/aryptr/aryptr2.html and
http://c-faq. <http://c-faq.com/aryptr/aryptrequiv.html>
com/aryptr/aryptrequiv.html somewhat educational. (And
the rest of that FAQ come to think of it.

-- 
PJH

http://shabbleland. <http://shabbleland.myminicity.com/com>
myminicity.com/com
http://www.chavgang <http://www.chavgangs.com/register.php?referer=9375>
s.com/register.php?referer=9375





[Non-text portions of this message have been removed]

Reply via email to