// enum_test - small test for the enum datatype

#include <stdio.h>

// single constant as enum
enum { BITS_PER_COLOR = 8 };

// index of the single color channels
enum { RED, GREEN, BLUE };

// some palette indices for predefined colors
enum _ColorPalette_ { CYAN = 3, MAGENTA, YELLOW, NUM_ENTRIES };

typedef enum _ColorPalette_ ColorPalette;

int main(int argc,char *argv[])
{
  ColorPalette a_color = YELLOW;
  unsigned *colors = (unsigned *)malloc(sizeof(unsigned) * 
                                        NUM_ENTRIES);

  unsigned full_brightness = 0x0;
  unsigned count = BITS_PER_COLOR;

  while(count--)
    full_brightness = (full_brightness << 1) | 0x01;

  colors[CYAN] = (full_brightness << (BITS_PER_COLOR * GREEN)) |
                 (full_brightness << (BITS_PER_COLOR * BLUE));
  
  colors[MAGENTA] = (full_brightness << (BITS_PER_COLOR * RED)) |
                    (full_brightness << (BITS_PER_COLOR * BLUE));
  
  colors[YELLOW] = (full_brightness << (BITS_PER_COLOR * GREEN)) |
                   (full_brightness << (BITS_PER_COLOR * RED));
  
  printf("Cyan has index %u and is defined as %x\n",CYAN,
         colors[CYAN]);
  printf("Magenta has index %u and is defined as %x\n",MAGENTA,
         colors[MAGENTA]);
  printf("Yellow has index %u and is defined as %x\n",YELLOW,
         colors[YELLOW]);
  printf("a_color has the value %u\n",a_color);
  return(0);
}
