Union Of Bitfields

Hello!

I have a question regarding bitfields. Say I wanted a struct, "Color," that represents a 16 - bit color. It would look something like this:

struct Color{
  uint16_t color=0;
}

Now, instead, I would like to represent the R,G, and B fields (in RGB565 format). Now, the code looks something like this:

struct Color{
  byte r : 5, g : 6, b : 5;
}

Now, say I would like both representations. The code that should do this is here:

struct Color{
  union{
    struct{
      byte r : 5, g : 6, b : 5;
    };
    uint16_t color;
  }
}

But sadly, this does not work as intended (the fields r, g, and b are not public).

How do I do this correctly? of course, I could manually calculate the 16 bit representation, but it would be faster to just use the raw data (which should already be in RGB ordering!)
Thanks!

Fuzzyzilla:
But sadly, this does not work as intended (the fields r, g, and b are not public).

struct Color{
  union{
    struct{
      byte r : 5, g : 6, b : 5;
    };
    uint16_t color;
  };
};

static Color c1;

void setup( void ) 
{ 
  c1.color = 0;
  c1.r = 13;
  c1.g = 13;
  c1.b = 13;
}

void loop( void ) { }
Sketch uses 456 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 11 bytes (0%) of dynamic memory, leaving 2037 bytes for local variables. Maximum is 2048 bytes.

They are public.

How do I do this correctly?

Whoops! Stupid mistake. I forgot to put a semicolon after the union declaration, causing an error.

Ok, works as expected! Sorry!