Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operands are not assignment compatible

Tags:

c

z80

I have the following code:

struct something {
  char *(*choices)[2];
};
char* arr[2] = {"foo", "bar"};

int main(void) {
  struct something obj;
  obj.choices = &arr;
  return 0;
}

When I compile this using a normal C compiler (gcc), I get no errors. However, I am compiling for the Z80, and it raises a ERROR (152) Operands are not assignment compatible, which is described as:

An attempt was made to assign a value whose type cannot be promoted to the type of the destination.

I fail to understand how the types of &arr and char *(*choices)[2] could differ. What can I do to fix this ?

(I'm using the Zilog z80 compiler, which is part of ZDS 5.2.0)

like image 612
TrakJohnson Avatar asked May 11 '19 12:05

TrakJohnson


Video Answer


1 Answers

It's probably some kind of weird compiler bug. This code compiles fine:

struct something {
  char *** choices;
};

char * arr[2] = {"foo", "bar"};

int main(void) {
  struct something obj;
  obj.choices = &arr;
  return 0;
}

And I'm afraid that it's the only workaround that is the most compatible with original idea.

like image 138
Kamila Szewczyk Avatar answered Sep 19 '22 18:09

Kamila Szewczyk