Skip to main content
added 193 characters in body
Source Link
jdt
  • 2.4k
  • 5
  • 20

I think the way you applied the macro in this case is spot on. My only concern is the mixture of integer and floating-point values. I would recommend replacing it with something like this that also looks a bit neater:

void fill_color_gcs(xcb_connection_t * c, xcb_window_t w, xcb_screen_t * s, 
    xcb_gcontext_t * col) {
    COLOR_GC(0, 0.00, 0.00, 0.00);
    COLOR_GC(1, 1.00, 1.00, 1.00);
    COLOR_GC(2, 1.00, 0.00, 0.00);
    COLOR_GC(3, 0.00, 1.00, 1.00);
    COLOR_GC(4, 1.00, 0.00, 1.00);
    COLOR_GC(5, 0.00, 1.00, 0.00);
    COLOR_GC(6, 0.00, 0.00, 1.00);
    COLOR_GC(7, 1.00, 1.00, 0.00);
    COLOR_GC(8, 1.00, 0.50, 0.00);
    COLOR_GC(9, 0.50, 0.25, 0.25);
    COLOR_GC(10, 1.00, 0.50, 0.50);
    COLOR_GC(11, 0.25, 0.25, 0.25);
    COLOR_GC(12, 0.50, 0.50, 0.50);
    COLOR_GC(13, 0.50, 1.00, 0.50);
    COLOR_GC(14, 0.50, 0.50, 1.00);
    COLOR_GC(15, 0.75, 0.75, 0.75);
}

I agree with Claus Bönnhoff suggestion of using a lookup table, but this will create unnecessary code if the colors will never change. I’m beginning to understand why your question was downvoted.

I think the way you applied the macro in this case is spot on. My only concern is the mixture of integer and floating-point values. I would recommend replacing it with something like this that also looks a bit neater:

void fill_color_gcs(xcb_connection_t * c, xcb_window_t w, xcb_screen_t * s, 
    xcb_gcontext_t * col) {
    COLOR_GC(0, 0.00, 0.00, 0.00);
    COLOR_GC(1, 1.00, 1.00, 1.00);
    COLOR_GC(2, 1.00, 0.00, 0.00);
    COLOR_GC(3, 0.00, 1.00, 1.00);
    COLOR_GC(4, 1.00, 0.00, 1.00);
    COLOR_GC(5, 0.00, 1.00, 0.00);
    COLOR_GC(6, 0.00, 0.00, 1.00);
    COLOR_GC(7, 1.00, 1.00, 0.00);
    COLOR_GC(8, 1.00, 0.50, 0.00);
    COLOR_GC(9, 0.50, 0.25, 0.25);
    COLOR_GC(10, 1.00, 0.50, 0.50);
    COLOR_GC(11, 0.25, 0.25, 0.25);
    COLOR_GC(12, 0.50, 0.50, 0.50);
    COLOR_GC(13, 0.50, 1.00, 0.50);
    COLOR_GC(14, 0.50, 0.50, 1.00);
    COLOR_GC(15, 0.75, 0.75, 0.75);
}

I think the way you applied the macro in this case is spot on. My only concern is the mixture of integer and floating-point values. I would recommend replacing it with something like this that also looks a bit neater:

void fill_color_gcs(xcb_connection_t * c, xcb_window_t w, xcb_screen_t * s, 
    xcb_gcontext_t * col) {
    COLOR_GC(0, 0.00, 0.00, 0.00);
    COLOR_GC(1, 1.00, 1.00, 1.00);
    COLOR_GC(2, 1.00, 0.00, 0.00);
    COLOR_GC(3, 0.00, 1.00, 1.00);
    COLOR_GC(4, 1.00, 0.00, 1.00);
    COLOR_GC(5, 0.00, 1.00, 0.00);
    COLOR_GC(6, 0.00, 0.00, 1.00);
    COLOR_GC(7, 1.00, 1.00, 0.00);
    COLOR_GC(8, 1.00, 0.50, 0.00);
    COLOR_GC(9, 0.50, 0.25, 0.25);
    COLOR_GC(10, 1.00, 0.50, 0.50);
    COLOR_GC(11, 0.25, 0.25, 0.25);
    COLOR_GC(12, 0.50, 0.50, 0.50);
    COLOR_GC(13, 0.50, 1.00, 0.50);
    COLOR_GC(14, 0.50, 0.50, 1.00);
    COLOR_GC(15, 0.75, 0.75, 0.75);
}

I agree with Claus Bönnhoff suggestion of using a lookup table, but this will create unnecessary code if the colors will never change. I’m beginning to understand why your question was downvoted.

Source Link
jdt
  • 2.4k
  • 5
  • 20

I think the way you applied the macro in this case is spot on. My only concern is the mixture of integer and floating-point values. I would recommend replacing it with something like this that also looks a bit neater:

void fill_color_gcs(xcb_connection_t * c, xcb_window_t w, xcb_screen_t * s, 
    xcb_gcontext_t * col) {
    COLOR_GC(0, 0.00, 0.00, 0.00);
    COLOR_GC(1, 1.00, 1.00, 1.00);
    COLOR_GC(2, 1.00, 0.00, 0.00);
    COLOR_GC(3, 0.00, 1.00, 1.00);
    COLOR_GC(4, 1.00, 0.00, 1.00);
    COLOR_GC(5, 0.00, 1.00, 0.00);
    COLOR_GC(6, 0.00, 0.00, 1.00);
    COLOR_GC(7, 1.00, 1.00, 0.00);
    COLOR_GC(8, 1.00, 0.50, 0.00);
    COLOR_GC(9, 0.50, 0.25, 0.25);
    COLOR_GC(10, 1.00, 0.50, 0.50);
    COLOR_GC(11, 0.25, 0.25, 0.25);
    COLOR_GC(12, 0.50, 0.50, 0.50);
    COLOR_GC(13, 0.50, 1.00, 0.50);
    COLOR_GC(14, 0.50, 0.50, 1.00);
    COLOR_GC(15, 0.75, 0.75, 0.75);
}