trouble creating multidimensional array

Hi,

Trying to set up a multidimensional array for a POV glyph writer.

Each sub-array is a different size and that's were I seem to be struggling. Do 2D arrays need to be uniform in size?

I have been trying like this:

PROGMEM prog_uint16_t povset[95][] = { // starts from ascii char 32 {0, 0, 0, 0 } // ' ' ascii char 32 {0, 0, 7678, 7678, 0, 0, 0 } // '!' ascii char 33 {0, 30, 30, 0, 0, 30, 30, 0 } // '"' ascii char 34 {0, 768, 816, 7984, 2032, 894, 6966, 8112, 1016, 830, 818, 48, 0 } // '#' ascii char 35 {0, 0, 0, 3312, 6392, 6552, 32766, 6552, 7984, 3840, 0 } // '$' ascii char 36 {0, 60, 126, 66, 6210, 7294, 3900, 896, 480, 112, 3900, 8078, 4230, 4224, 8064, 3840 } // '%' ascii char 37 {0, 1920, 4032, 7420, 6270, 6374, 6342, 7558, 8070, 3852, 8128, 6592, 4096, 0 } // '&' ascii char 38 {0, 30, 30, 0, 0 } // ''' ascii char 39 .... ....

I get the error: declaration of 'povset' as multidimensional array must have bounds for all dimensions except the first

How is it possible to use 2d arrays of different sizes?

Iliffe vectors

Thank you, but there doesn't seem to be a lot of documentation about Iliffe vectors.

Could you provide me with a short example of how I would change my code?

Is it just a matter of placing a "*" after the data type?

Cheers

I only got got 58000 hits with google "iliffe vector c"

Nope,

Still stuck but I think i’m getting somewhere although it’s all quite new to me using pointers and retrieving from Progmem.

So far I have made a bunch of arrays like this:

PROGMEM prog_uint16_t char32[4] = {0, 0, 0, 0 }; // ’ ’ ascii char 32
PROGMEM prog_uint16_t char33[7] = {0, 0, 7678, 7678, 0, 0, 0 }; // ‘!’ ascii char 33
PROGMEM prog_uint16_t char34[8] = {0, 30, 30, 0, 0, 30, 30, 0 }; // ‘"’ ascii char 34

Then I have a pointer array:

PROGMEM prog_uint16_t* charArray = {char32, char33, char34, char35, … …

Then I create a buffer:

prog_uint16_t charBuffer[20];

The next bit is where I am stuck - moving ints from progmem into the buffer. From what I’ve read regarding strings in Progmem it should be something like this:

  for (int i = 0; i <sizeof(charArray[i]); i++)
  {
    memcpy_P(charBuffer, (byte*)pgm_read_byte(&(charArray[i])), prog_uint16_t); 
  }

But I get an error for this line saying:

Moderator edit: removed unnecessary italics. Please use code tags

141: error: expected primary-expression before ‘)’ token -

This is a bit baffling to me - which “)” is the error refering to?

How big do you think sizeof(char_array[i]) is going to be?

I thought sizeof(charArray[i]) would look at the array pointed to - char32[4]?

I suspect the fact that you asked me this question means I'm incorrect!

Is that because I'm dealing with ints not bytes? Would I need to half the array size as it would count the number of bytes not ints?

Or is it that you can't access the array size through a pointer like that?

prog_uint16_t* charArray[]

All elements in the array are the same size - 2 bytes. You can not get the length of a array pointed to by a pointer. You must find some other way to convey that information.

Yay! I think I've sorted it:

As well as the original arrays, I added an array of array lengths into Progmem...

PROGMEM prog_uint8_t ArraySize[] = {4, 7, 8, 13, 11, 16....

Then to retrieve the integers in each array I used this kind of setup:

unsigned int charBuffer[20];
byte myArrayLength;
  
  byte index = 5;

  myArrayLength = pgm_read_byte_near(ArraySize + index);

memcpy_P(charBuffer, (uint16_t*)pgm_read_word(&charArray[index]), myArrayLength*2);

It seems to work, but is this an efficient way to do it?