<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>2 dimentional arrays</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/13783/2-dimentional-arrays</link><description> Has anyone found a way to pass 2 dimentional arrays to a function? My arrays are stored in code and I need to pass them to a function to display them. 
 
Gary Martin </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: 2 dimentional arrays</title><link>https://community.arm.com/thread/84008?ContentTypeID=1</link><pubDate>Thu, 26 Oct 2000 08:10:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:35de9597-9ab6-4dbe-9a14-7852ca1aa89f</guid><dc:creator>Ted Dubroff</dc:creator><description>&lt;p&gt;Whoops, you are quite right.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 dimentional arrays</title><link>https://community.arm.com/thread/53400?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2000 21:36:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0486bfef-3c24-49d6-a5cf-1e7d3161572a</guid><dc:creator>Keil Support</dc:creator><description>&lt;p&gt;Yes,&lt;br /&gt;
&lt;br /&gt;
Without testing, it works.  But when tested it doesn&amp;#39;t.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
void func(int ** pArray2d)
&lt;/pre&gt;
&lt;br /&gt;
is a function that expects pArray2d to be a pointer to a pointer to an int.  This is NOT what is needed.&lt;br /&gt;
&lt;br /&gt;
This is one of the areas of C that most confuses people.  In most contexts, the compiler converts a reference to an array into a pointer to the first element of the array.  This leads people to think that arrays and pointers are equivalent.  They aren&amp;#39;t.&lt;br /&gt;
&lt;br /&gt;
In C, multi-dimensional arrays are implemented as arrays of arrays.  So the first element of a two-dimensional array is a one-dimensional array.  Therefore, a pointer to the first element of a two-dimensional array is a pointer to a one-dimensional array - not a pointer to a pointer.&lt;br /&gt;
&lt;br /&gt;
Here is a working example:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
unsigned char _2d_array [5][5];

void func (unsigned char (*x)[5])
{
x [0][0] = 1;
x [1][0] = 6;
x [2][1] = 12;
}

void main (void)
{
func (_2d_array);

while (1);
}
&lt;/pre&gt;
&lt;br /&gt;
Note that func:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
void func (unsigned char (*x)[5])
&lt;/pre&gt;
&lt;br /&gt;
is declared with an argument that is a pointer to an array of 5 items.  This is required so that the compiler knows how to handle the multiple dimensions.&lt;br /&gt;
&lt;br /&gt;
The parentheses around *x are required.  We want x to be a pointer to an array of 5 unsigned chars.  Without the parentheses, the &amp;#39;[]&amp;#39; would take precedence over the &amp;#39;*&amp;#39;, and x would be an array of 5 pointers to unsigned char.&lt;br /&gt;
&lt;br /&gt;
Hope this helps.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Keil Support&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 dimentional arrays</title><link>https://community.arm.com/thread/71305?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2000 18:32:55 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:99b15e72-2602-4c04-a44c-0e10e3126fc9</guid><dc:creator>Gary Martin</dc:creator><description>&lt;p&gt;Yes it should, but it dosen&amp;#39;t.&lt;br /&gt;
&lt;br /&gt;
Gary Martin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 dimentional arrays</title><link>https://community.arm.com/thread/71304?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2000 18:32:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:08099fd5-671d-4dae-bba1-2e66f878fa9e</guid><dc:creator>Gary Martin</dc:creator><description>&lt;p&gt;You would thing so, but try doing with Keil.&lt;br /&gt;
&lt;br /&gt;
GAry Martin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 dimentional arrays</title><link>https://community.arm.com/thread/36945?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2000 13:10:03 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ade3a7fb-4518-4019-bc78-2414fbe6d79a</guid><dc:creator>Ted Dubroff</dc:creator><description>&lt;p&gt;Without testing, the code below should work:&lt;br /&gt;
&lt;br /&gt;
// Data&lt;br /&gt;
int array2d[5][5];&lt;br /&gt;
&lt;br /&gt;
// Function Prototype&lt;br /&gt;
void func(int ** pArray2d);&lt;br /&gt;
&lt;br /&gt;
// Main function&lt;br /&gt;
void main(void)&lt;br /&gt;
{&lt;br /&gt;
    func(array2d);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void func(int ** pArray2d)&lt;br /&gt;
{&lt;br /&gt;
    pArray2d[0][0] = 3;&lt;br /&gt;
    pArray2d[0][1] = 4;  // etc...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 dimentional arrays</title><link>https://community.arm.com/thread/36941?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2000 13:02:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b2ffa7cc-2793-4aa5-bf33-ab69fdeb0720</guid><dc:creator>Mark Odell</dc:creator><description>&lt;p&gt;This is really a C question, see:&lt;br /&gt;
 &lt;br /&gt;
&lt;a href="http://www.eskimo.com/~scs/C-faq/q6.18.html" target="_blank"&gt;http://www.eskimo.com/~scs/C-faq/q6.18.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
- Mark&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>