The main difficulty with you is that the assignment operation for arrays is not defined, and curly braces are needed to initialize the variable when it is declared.
However, if you remember about the preprocessor, your initialization can be written like this:
#define COLOR(r,g,b) { r, g, b } #define RED COLOR(255, 0, 0) #define GREEN COLOR(0, 255, 0) #define BLUE COLOR(0, 0, 255) #define BLACK COLOR(0, 0, 0) #define WHITE COLOR(255, 255, 255) const unsigned char red[] = RED, green[] = GREEN, blue[] = BLUE, black[] = BLACK, white[] = WHITE; const unsigned char my_color[] = RED; // <- No error int main() { // ... }
If you want to use color assignments in the executable part of the program, then you can go a little further and write, for example,
(since structures can be assigned)
// ΠΌΠ°ΠΊΡΠΎΡΡ Π΄Π»Ρ ΡΠ²Π΅ΡΠΎΠ² ΠΎΡΡΠ°Π»ΠΈΡΡ ΠΏΡΠ΅ΠΆΠ½ΠΈΠΌΠΈ struct color { unsigned char color[3]; }; const color red = RED, green = GREEN, blue = BLUE, black = BLACK, white = WHITE, my_color = RED; int main() { // ΡΠ΅ΠΏΠ΅ΡΡ ΡΠ²Π΅ΡΠ°ΠΌΠΈ ΠΌΠΎΠΆΠ½ΠΎ ΠΌΠ°Π½ΠΈΠΏΡΠ»ΠΈΡΠΎΠ²Π°ΡΡ ΡΠ°ΠΊΠΈΠΌ ΠΎΠ±ΡΠ°Π·ΠΎΠΌ color x, y = BLACK, z; x = (color)WHITE; y = (color)COLOR(1,2,3); z = my_color; z.color[1] = 200; }