The problem is that you are calling malloc outside function.
This will solve your problem:
typedef struct {
int x;
int y;
char style;
} Pixel;
int main(void) {
Pixel *pixels = malloc(9 * 128);
}
In C you cannot call function on variable init, if variable is not inside any function.
int a = 5; //OK
int b = myfunc(); //ERROR, this was your case
int main() {
int c = 5; //OK
int d = myfunc(); //OK
}
As from code inspect, I assume you think that your sizeof(Pixel)
is 9
bytes but this may not be the case. When you call your malloc, use this code:
Pixel *pixels = malloc(sizeof(Pixel) * 128);
This code will allocate memory for 128 Pixel
structures in a single row on any platform.
Further reading:
Structure padding and packing
Do I cast the result of malloc?