- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, all!
I declared a two dimensional array.
int a[2][3];
I just expected 'a' is a type of 'int **'. However, icc gave me the info that 'a' is a type of 'int (*)[3]'.
I'm confused. What's the meaning of 'int (*)[3]'? How could 'a' be of that type?
Thanks in advance!
I declared a two dimensional array.
int a[2][3];
I just expected 'a' is a type of 'int **'. However, icc gave me the info that 'a' is a type of 'int (*)[3]'.
I'm confused. What's the meaning of 'int (*)[3]'? How could 'a' be of that type?
Thanks in advance!
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Have a look at:
http://donchel.wordpress.com/2010/10/28/multidimensional-arrays-and-pointer/
The C standard apparently says this:
My impression is that the allocation scheme for multidimensional static arrays is not defined in the C standard. The assumption that int a[2][3] is equivalent to 2 * 6 = 6 ints in a sequence in memory is usually correct (I have tested this with the gcc and icpc compilers), but must not hold in every case.
I think that this might have something to do with the fact that a is not of type int**, but int (*)[3] in these cases.
But casting the pointer a or a[0] to an int * does work and produces the right results.
I hope this is of help to you.
Have a look at:
http://donchel.wordpress.com/2010/10/28/multidimensional-arrays-and-pointer/
The C standard apparently says this:
6.5.2.1 Array subscriptingTogether with int * is not identical to int [], this is what the compiler is telling you, I think.
Constraints
3 Successive subscript operators designate an element of a multidimensional
array object.
If E is an n-dimensional array (n >= 2) with dimensions i * j * . . . * k,
then E (used a s other than an lvalue) is converted to a pointer to an
(n - 1)-dimensional array with dimensions j * . . . * k.
If the unary * operator is applied to this pointer explicitly, or
implicitly as a result of subscripting, the result is the pointed-to
(n - 1)-dimensional array, which itself is converted into a pointer if
used as other than an lvalue. It follows from this that arrays are stored
in row-major order (last subscript varies fastest).
My impression is that the allocation scheme for multidimensional static arrays is not defined in the C standard. The assumption that int a[2][3] is equivalent to 2 * 6 = 6 ints in a sequence in memory is usually correct (I have tested this with the gcc and icpc compilers), but must not hold in every case.
I think that this might have something to do with the fact that a is not of type int**, but int (*)[3] in these cases.
But casting the pointer a or a[0] to an int * does work and produces the right results.
I hope this is of help to you.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page