2

Very specific problem, possibly due to my generally poor understanding of multidimensional arrays in C. I've got this code:

int io_pipes[NUM_IO_PROC][n][2][2];

for (int i = 0; i < n; ++i) {
    int pipes[NUM_IO_PROC][2][2];
    for (int j = 0; j < NUM_IO_PROC; ++j) pipes[j] = io_pipes[j][i];
}

There's some stuff missing, of course (like what happens to the pipes variable). Problem is that on line 5 there, I get a compiler error that say "incompatible type in assignment." I'd like it if the compiler gave me more information because as far as I know, pipes[j] and io_pipes[j][i] are both of type int[2][2].

3
  • Do you want to copy the data, or just 'make pointers'? Commented Oct 25, 2011 at 5:03
  • I think more correctly pipes[j] and io_pipes[j][i] are both of type const int[2][2], which means you cannot assign to pipes[j]. Commented Oct 25, 2011 at 5:08
  • I went with the struct version, which allows me to do exactly what I wanted rather than the memcpy version below, and makes better sense overall. Commented Oct 26, 2011 at 20:58

2 Answers 2

1

You cannot 'assign' arrays. (At least, what I think you're trying to do.)

You'll need to copy each element, one by one. Maybe you can use one of the existing library functions for this task?

for(int j = 0; j < NUM_IO_PROC; ++j)
    memcpy(&pipes[j], &io_pipes[j][i], sizeof pipes[j]);
Sign up to request clarification or add additional context in comments.

1 Comment

memcpy(&pipes[j], &io_pipes[j][i], sizeof pipes[j]); is probably clearer.
0

The arrays identifier is internally treadted as pointer to base address, but unlike pointers they cannot be assigned a new address value which you are trying to do in pipes[j] = io_pipes[j][i];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.