<?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[private member of anonymous struct in union]]></title><description><![CDATA[<p>Hi,<br />
Ich möchte innerhalb eines Speicherbereiches einige Register durch überlagern mit einer Klasse oder Stucktur ansprechen.Warum kann ich meine offsets-variablen nicht vor Zugriff schützen (noch lieber wäre es mir sie garnicht erst zu benennen).</p>
<pre><code class="language-cpp">typedef char uint8_t;
class test
{
	union
	{
		struct{
			private:
				uint8_t _offset_ra[7];
			public:
				uint8_t registera;
		};
		struct{
			private:
				uint8_t _offset_rb[6];
			public:
				uint8_t registerb;
		};
	};
};
</code></pre>
<p>gcc meldet beim beispiel:</p>
<pre><code>error: private member ‘uint8_t test::&lt;anonymous union&gt;::&lt;anonymous struct&gt;::_offset_ra [7]’ in anonymous union
</code></pre>
<p>und entsprechendes für _offset_rb</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/234412/private-member-of-anonymous-struct-in-union</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 10:20:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/234412.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 17 Feb 2009 17:08:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to private member of anonymous struct in union on Tue, 17 Feb 2009 17:08:23 GMT]]></title><description><![CDATA[<p>Hi,<br />
Ich möchte innerhalb eines Speicherbereiches einige Register durch überlagern mit einer Klasse oder Stucktur ansprechen.Warum kann ich meine offsets-variablen nicht vor Zugriff schützen (noch lieber wäre es mir sie garnicht erst zu benennen).</p>
<pre><code class="language-cpp">typedef char uint8_t;
class test
{
	union
	{
		struct{
			private:
				uint8_t _offset_ra[7];
			public:
				uint8_t registera;
		};
		struct{
			private:
				uint8_t _offset_rb[6];
			public:
				uint8_t registerb;
		};
	};
};
</code></pre>
<p>gcc meldet beim beispiel:</p>
<pre><code>error: private member ‘uint8_t test::&lt;anonymous union&gt;::&lt;anonymous struct&gt;::_offset_ra [7]’ in anonymous union
</code></pre>
<p>und entsprechendes für _offset_rb</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1665403</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1665403</guid><dc:creator><![CDATA[k_the_first]]></dc:creator><pubDate>Tue, 17 Feb 2009 17:08:23 GMT</pubDate></item><item><title><![CDATA[Reply to private member of anonymous struct in union on Tue, 17 Feb 2009 17:14:27 GMT]]></title><description><![CDATA[<p>k_the_first schrieb:</p>
<blockquote>
<pre><code class="language-cpp">typedef char uint8_t;
class test
{
	union
	{
		struct{
			private:
				uint8_t _offset_ra[7];
			public:
				uint8_t registera;
		} s1;
		struct{
			private:
				uint8_t _offset_rb[6];
			public:
				uint8_t registerb;
		} s2;
	} un;
};
</code></pre>
</blockquote>
<p>Dann probiers mal so, wobei du un möglicherweise auch weglassen kannst, heißt, dass du der union nicht unbedingt einen Namen geben musst. Bin mir da aber gerade nicht sicher, wie das bei C++ aussieht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1665404</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1665404</guid><dc:creator><![CDATA[feigling]]></dc:creator><pubDate>Tue, 17 Feb 2009 17:14:27 GMT</pubDate></item><item><title><![CDATA[Reply to private member of anonymous struct in union on Tue, 17 Feb 2009 17:56:35 GMT]]></title><description><![CDATA[<p>Mit benannten Strukturen akzeptiert es der Compiler, leider passt das nicht zum Rest des Codes da ich an anderer Stelle diereckt mit</p>
<pre><code class="language-cpp">test instance;
instance.registera = 27;
</code></pre>
<p>darauf zugreife, ohne private: akzeptiert der Compiler es ebenfalls nur erlaubt das den Zugriff auf den Offset was ich gern verhindern möchte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1665415</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1665415</guid><dc:creator><![CDATA[k_the_first]]></dc:creator><pubDate>Tue, 17 Feb 2009 17:56:35 GMT</pubDate></item><item><title><![CDATA[Reply to private member of anonymous struct in union on Wed, 18 Feb 2009 13:00:25 GMT]]></title><description><![CDATA[<p>Eine <code>union</code> darf nur PODs als Member enthalten. Da du das Schlüsselwort <code>private</code> in den <code>struct</code> s verwendest, hast du keinen POD mehr.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1665704</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1665704</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 18 Feb 2009 13:00:25 GMT</pubDate></item></channel></rss>