Error tring to send an array to function

Hi there!
In my efforts to build some function that get an array from type integer ( =void func(int array[32][32])
But the compiler keep sending me weird errors. Tried several things like not defining the size of the array but it doesn't work...errors like invalid conversion of type 'int to int- [32]'
Pkease help!!!

Thanks and stuff..

can we see the code you are working on for this? in order to do this well, we need to know where you are coming from.

an int array[32][32] takes 32 x 32 x 2 bytes of RAM = 2048 which is all the RAM an UNO has.

For these large structures there are three options:

  • pass a pointer to the structure
  • use a reference or
  • use the array as a global variable.

BTW: which board do you use?

kimkash:
Hi there!
In my efforts to build some function that get an array from type integer ( =void func(int array[32][32])
But the compiler keep sending me weird errors. Tried several things like not defining the size of the array but it doesn't work...errors like invalid conversion of type 'int to int1. [32]'
Pkease help!!!

Thanks and stuff..
[/quote]
In C/C++, arrays are second class citizens. Instead of passing the array, you are passing a pointer to the array, and the declaration is changed to be a pointer by the compiler. As others have mentioned, you likely don't have that much memory to hold a 32x32x2 byte array in an AVR based processor or 32x32x4 byte array in an Arm processor.

Hi again
so first-I'm running Arduino Mega 2560 Rev3 so the RAM isn't an issue for as long as if the array really takes 2048 and not more...the Mega Rev3 has 8kb of SRAM.
second,this is the code:

/*  This program cycles through all the LEDs in a regular-multiplexed 3x3 LED matrix.
*/

int array[3][3]={{1,1,1},{1,1,1},{1,1,1}};

void setup()
{
  for (int i=0;i<11;i+=2) pinMode(i,OUTPUT);
  for (int i=0;i<5;i+=2) digitalWrite(i,LOW);
  for (int i=6;i<11;i+=2) digitalWrite(i,HIGH);
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
}

void loop()
{
  refresh(array[3][3]);
  delay(1000);
}

void refresh(int leds[3][3])
{
  for (int i=0;i<3;i++)
  {
    for (int j=0;j<3;j++)
    {
      if (leds[i][j]==1)
      {
        digitalWrite(i,HIGH);
        digitalWrite(j,LOW);
        delay(50);
        digitalWrite(i,LOW);
        digitalWrite(j,HIGH);
      }
    }
  }
}

As you'll try to compile,you'll see the error. try to correct it to any of the following

array

array[][]

array[][3]

array[3][]

array[3][3]

Thank your for your help!
and sorry the first Q was with a lot of spelling mistakes...wrote it via mobile during pickup to work...

If you want to pass the array to the function then you would just use the array name as the argument value:

refresh(array);

You don't have to pass the array to the function, as it is a global variable.

Why pass the address of a global array to a function?

Declare your int array as a byte array?

Why hardcode values that can be determined at compile time -

#define ARRAY_ENTRIES(ARRAY)     (sizeof(ARRAY) / sizeof(ARRAY[0]))

int array[][3]  =
{
      { 1, 1, 1 }
    , { 1, 1, 1 }
    , { 1, 1, 1 }
    , { 1, 1, 1 }
};

const size_t    kROWS       = ARRAY_ENTRIES(array);
const size_t    kCOLUMNS    = ARRAY_ENTRIES(array[0]);

EDIT: Removed earlier post as I thought I'd made a mistake. Looked it over and realized it was correct so ...

never occurred to me that I'm using it at global scope :cold_sweat:
but the last response by lloyddean really confused me.....not understood a word...

kimkash:
never occurred to me that I'm using it at global scope :cold_sweat:
but the last response by lloyddean really confused me.....not understood a word...

You can declare an array variable like this:

int someArray[3] = { 1, 2, 3 };

but you don't have to specify the size when you are initialising it at the same time:

int someArray[] = { 1, 2, 3 };

the compiler works it out for you.

It's purely stylistic, and you should stick with what is comfortable. In fact, I'd say version 1 is better, as it's self-documenting.

It's purely stylistic

No, it isn't. If you know that the array should contain n elements, say so. That way, the compiler will make sure it contains n elements. If you don't specify the size, and provide more or less initializers that you think you did, the compiler will supply missing ones or complain about extras.

For an array size of three, it's relatively easy to see that there are 3 initializers. For an array size of 300, it's a lot harder.