0

I'm using the following to allow me to choose which 2D array I use, dynamically.

const prog_uint16_t (*p)[8];
p = arrayname;

This works fine for a 2D array of size [3][8], however I require [10][1025].
When I try this:

const prog_uint16_t (*p)[1025];
p = arrayname;

I get a "Cannot convert" error.

Any ideas? Thanks!

EDIT:

Here's the declaration of the 2D array that works. The one that doesn't is declared the same way, just with a different number of entries ([10][1025]).

const prog_uint16_t TRI[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}};

Thanks!

5
  • 5
    show us the declaration of arrayname. Also, (*p)[8] is not a pointer to a 2d array. cdecl.org Commented Jan 31, 2014 at 19:14
  • 1
    This is not a 2-D array. It's a 1D array of pointers to prog_uint16_t. Commented Jan 31, 2014 at 19:29
  • @ErikJohnson: No, p is a pointer to array of 8 const prog_uint16_t Commented Jan 31, 2014 at 19:38
  • The array I am trying to point to is a 2D array. See Edit! Commented Jan 31, 2014 at 20:51
  • const prog_uint16_t (*p)[x][y]; <- that's a pointer to a 2d array Commented Jan 31, 2014 at 20:55

2 Answers 2

1

You Cant change Size and type of constant pointer of course you can change data pointed or

else but Cant resize this type ofp pointer

look this code maybe help you

const int x;             // x cannot be modified

const int* pX = &x;      // pX is the address of a const int
                 // and can't be used to change an int

 *pX = 4;                 // illegal - can't use pX to change an int

 int* pInt;       // address of normal int

  pInt = pX;       // illegal - cannot convert from const int* to int*

be successfull

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for replying. I'm not trying to resize the pointer, I get the error simply when trying to point the pointer to the array, despite declaring it as the correct size..
0

A pointer to a two dimensional array would take the form:

prog_uint16_t (*p)[x][y];

So, for example:

const prog_uint16_t array[1][2] = {{1,2}};
const prog_uint16_t (*p)[1][2] = &array;

2 Comments

cannot convert 'const prog_int16_t ()[10][1025] {aka const short int ()[10][1025]}' to 'const prog_uint16_t ()[10][1025] {aka const short unsigned int ()[10][1025]}' in assignment
@mattomatto: either your declaration or assignment is wrong, but you haven't shown us.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.