<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Anonymous structs]]></title><description><![CDATA[<p>I need to do that:</p>
<pre><code class="language-cpp">union tColor
{
  struct //anonymous struct
  {
    unsigned char r,g,b;
  };

  unsigned char channels[3];
};
</code></pre>
<p>This works as intended in MSVC:</p>
<pre><code class="language-cpp">tColor color;
color.r=100;
color.g=150;
color.b=200;
color.channels[1]==150; //true
</code></pre>
<p>But i still worry if this according to the C++ standard.</p>
<p>Also I wonder if I can use anonymous arrays:</p>
<pre><code class="language-cpp">union tColor
{
  struct
  {
    unsigned char r,g,b;
  };

  unsigned char[3]; //anonymous array ?
};
</code></pre>
<p>to do the following:</p>
<pre><code class="language-cpp">tColor color;
color.r=100;
color[1]=150;
color[2]=200;
</code></pre>
<p>Or I should define operator[] ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/208249/anonymous-structs</link><generator>RSS for Node</generator><lastBuildDate>Sun, 11 Oct 2026 15:45:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/208249.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Mar 2008 18:51:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anonymous structs on Sun, 16 Mar 2008 18:53:15 GMT]]></title><description><![CDATA[<p>I need to do that:</p>
<pre><code class="language-cpp">union tColor
{
  struct //anonymous struct
  {
    unsigned char r,g,b;
  };

  unsigned char channels[3];
};
</code></pre>
<p>This works as intended in MSVC:</p>
<pre><code class="language-cpp">tColor color;
color.r=100;
color.g=150;
color.b=200;
color.channels[1]==150; //true
</code></pre>
<p>But i still worry if this according to the C++ standard.</p>
<p>Also I wonder if I can use anonymous arrays:</p>
<pre><code class="language-cpp">union tColor
{
  struct
  {
    unsigned char r,g,b;
  };

  unsigned char[3]; //anonymous array ?
};
</code></pre>
<p>to do the following:</p>
<pre><code class="language-cpp">tColor color;
color.r=100;
color[1]=150;
color[2]=200;
</code></pre>
<p>Or I should define operator[] ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1475427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1475427</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Sun, 16 Mar 2008 18:53:15 GMT</pubDate></item></channel></rss>