Problem with pointing to large array

Status
Not open for further replies.

mattomatto

Well-known member
Hi all,

This may be a general syntax question but I couldn't get a good answer out of stack overflow so thought it might be a teensy issue!

I'm using a pointer to reference a 2D array, to allow me to switch which array I'm using on the fly. The code below works fine for an array of [3][8] as shown, but my arrays are [10][1025]. When I try the same code with these arrays, I get a cannot convert error. It's only the size of the arrays and pointer array that have changed.

Code:
const int JIM[3][8]={{10,20,30,40,50,60,70,80},{11,21,31,41,51,61,71,81},{12,22,32,42,52,62,72,82}};
const int BOB[3][8]={{15,25,35,45,55,65,75,86},{16,26,36,46,56,66,76,86},{17,27,37,47,57,67,77,87}};


 const prog_uint16_t (*p)[8];  //Declare array of pointers for size of sub-tables

void setup(){
  p=JIM;  //point p to start of JIM array
}

void loop(){
  Serial.println(p[0][6]);
  delay(1000);
  p=BOB;
  Serial.println(p[0][6]);
  delay(1000);
  p=JIM;
}


Perhaps a memory stack issue? Limitations of teensy?

Thanks!

Matt
 
As written your example doesn't compile because of the type mismatch: prog_uint16_t != int

However, the size limit question made me curious, so I ran the following. After altering the types, this compiled and ran fine for me on a T3.0 (using both Eclipse and Arduino). Just to check I also made a version with full array inits and it also ran fine.
Code:
#include "Arduino.h"

const uint16_t JIM[10][1025]={{10,20,30,40,50,60,70,80},{11,21,31,41,51,61,71,81},{12,22,32,42,52,62,72,82}};
const uint16_t BOB[10][1025]={{15,25,35,45,55,65,75,86},{16,26,36,46,56,66,76,86},{17,27,37,47,57,67,77,87}};


const uint16_t (*p)[1025];  // pointer to array of 1025 uint16_t

void setup(){
  p=JIM;  //point p to start of JIM array
}

void loop(){
  Serial.println(p[0][6]);
  delay(1000);
  Serial.println(p[1][6]);
  delay(1000);
  p=BOB;
  Serial.println(p[0][6]);
  delay(1000);
  Serial.println(p[1][6]);
  delay(1000);
  p=JIM;
}
 
Last edited:
Thanks nox771, it does indeed compile for me too now... I really must have been at it too long and made a silly mistake with the types.. Thanks for your time!
 
Status
Not open for further replies.
Back
Top