0

I am attempting to copy a return value from a method into an array of ints. (The method getPixelArray returns an int array of size 3.) Below is the offending section of my code. When I try to compile this code, I get the error

invalid lvalue in unary '&'

What could be going on? I was following the advice from this answer.

int temp[3];
memcpy(&temp, &(getPixelColor(width, height, x, y)), sizeof(temp));

EDIT: Here is the method.

int[3] getPixelColor(int width, int height, float x, float y) {
    int color[3] = {0, 0, 0}; // color of pixel

    // get color (omitted)

    return color;
}
Community
  • 1
  • 1

1 Answers1

0

The symbol tmp behaves like an int pointer.

And you cannot even return an array from a function, just a pointer:

int *getPixelCOlor(...

memcpy(temp, getPixelColor(width, height, x, y), sizeof temp);

getPixelColor returns the address of local automatic storage, which is usually in its stack frame, and will be destroyed with any subsequent function call. Like your own memcpy. Here be dragons.

SzG
  • 12,333
  • 4
  • 28
  • 41