C Array const unsigned char [] []

I turned around a bit for the exact syntax for this. I have one array defined as such:

const unsigned char ARR[SIZE][SIZE] = {...}

and I want to have it in an array so that I can do something with the effect

ARR2[0] = ARR

I tried const unsigned char ARR2[][SIZE][SIZE] = {ARR}and const unsigned char* ARR2[SIZE][SIZE] = {ARR}but none of them worked. Can someone point out the correct syntax for a constant array of constant two-dimensional arrays of unsigned characters?

+4
source share
3 answers

From your comment on the haccks post, it looks like you want this:

const unsigned char ARR[SIZE][SIZE] = {...};
const unsigned char (*ARR2[])[SIZE][SIZE] = {&ARR};

If you want ARR2yourself to be const, it would be like this:

const unsigned char (* const ARR2[])[SIZE][SIZE] = {&ARR};

, ARR[x][y] ARR2[0][x][y], (*ARR2[0])[x][y] (, , ARR2[0][0][x][y]).

, , , ARR2 ARR2[0] = ARR, ARR2[0] = &ARR ( , ). , ARR , a const unsigned char *, &ARR[0][0], ARR2[0] a const unsigned char (*)[SIZE][SIZE], &ARR, , .

+2

, , , , , / , . . : 6.5.16.1 .

, - memcpy() 'ing.

+1

try it

const unsigned char (* ARR2)[SIZE] = ARR; 

You mentioned in your comment that you want it to ARR2be an array that can contain the array ARRas the first element, but that is not possible . ARR- this is an array and it is converted to a pointer to it, the first element expects when it is the operand of the unary operator &and sizeof.

-1
source

Source: https://habr.com/ru/post/1670230/


All Articles