<?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[sizeof auf bit fields]]></title><description><![CDATA[<pre><code class="language-cpp">struct TilepointData
{
	uint16_t groundHeight;
	unsigned int boundaryFlag:1;
	unsigned int waterLevel:15;
	unsigned int flags:4;
	unsigned int groundTextureType:4;
	uint8_t textureDetails;
	unsigned int cliffTextureType:4;
	unsigned int layerHeight:4;
};

sizeof(struct TilepointData) // liefert 8 und nicht 7
</code></pre>
<p>Liegt das an der genannten compiler- bzw. architekturspezifischen Implementation von bit fields oder woran?</p>
<p>Des Weiteren wollte ich allgemein mal fragen, ob man bit fields eher meiden sollte. Im obrigen Fall lohnt es sich für mich, da viele Werter kleiner als 1 Byte sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/262023/sizeof-auf-bit-fields</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 00:40:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/262023.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 27 Feb 2010 12:13:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to sizeof auf bit fields on Sat, 27 Feb 2010 12:13:16 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">struct TilepointData
{
	uint16_t groundHeight;
	unsigned int boundaryFlag:1;
	unsigned int waterLevel:15;
	unsigned int flags:4;
	unsigned int groundTextureType:4;
	uint8_t textureDetails;
	unsigned int cliffTextureType:4;
	unsigned int layerHeight:4;
};

sizeof(struct TilepointData) // liefert 8 und nicht 7
</code></pre>
<p>Liegt das an der genannten compiler- bzw. architekturspezifischen Implementation von bit fields oder woran?</p>
<p>Des Weiteren wollte ich allgemein mal fragen, ob man bit fields eher meiden sollte. Im obrigen Fall lohnt es sich für mich, da viele Werter kleiner als 1 Byte sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862033</guid><dc:creator><![CDATA[Barade]]></dc:creator><pubDate>Sat, 27 Feb 2010 12:13:16 GMT</pubDate></item><item><title><![CDATA[Reply to sizeof auf bit fields on Sat, 27 Feb 2010 12:35:36 GMT]]></title><description><![CDATA[<p>könnte sein das es am padding liegt, welches eingefügt wird um die performance zu erhöhen, solange die struct nur innerhalb deiner software verwendet wird ist das so schon ok, anders sieht es aus, wenn damit daten mit anderer software(protokollen) ausgetauscht werden soll, da dann nicht sichergestellt ist, das die werte stimmen.</p>
<p><a href="http://en.wikipedia.org/wiki/Data_structure_alignment" rel="nofollow">http://en.wikipedia.org/wiki/Data_structure_alignment</a></p>
<p>lg lolo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862039</guid><dc:creator><![CDATA[noobLolo]]></dc:creator><pubDate>Sat, 27 Feb 2010 12:35:36 GMT</pubDate></item><item><title><![CDATA[Reply to sizeof auf bit fields on Sat, 27 Feb 2010 15:20:41 GMT]]></title><description><![CDATA[<p>Der Compiler füllt normalerweise immer nur die Bits eines Typs auf.</p>
<pre><code class="language-cpp">struct TilepointData
{
    uint16_t groundHeight;
    unsigned int boundaryFlag:1;
    unsigned int waterLevel:15;
    unsigned int flags:4;
    unsigned int groundTextureType:4; // 24/32 bits belegt
    uint8_t textureDetails;           // neuer Datentyp -&gt; wird nicht in den uint geschrieben
    unsigned int cliffTextureType:4;
    unsigned int layerHeight:4;
};
</code></pre>
<p>Versuch mal das:</p>
<pre><code class="language-cpp">struct TilepointData
{
    uint16_t groundHeight;
    unsigned int boundaryFlag:1;
    unsigned int waterLevel:15;
    unsigned int flags:4;
    unsigned int groundTextureType:4;
    unsigned int cliffTextureType:4;
    unsigned int layerHeight:4;
    uint8_t textureDetails;
};

sizeof(struct TilepointData)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1862089</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862089</guid><dc:creator><![CDATA[lustig]]></dc:creator><pubDate>Sat, 27 Feb 2010 15:20:41 GMT</pubDate></item><item><title><![CDATA[Reply to sizeof auf bit fields on Sat, 27 Feb 2010 15:27:41 GMT]]></title><description><![CDATA[<p>lustig schrieb:</p>
<blockquote>
<p>Der Compiler füllt normalerweise immer nur die Bits eines Typs auf.</p>
<pre><code class="language-cpp">struct TilepointData
{
    uint16_t groundHeight;
    unsigned int boundaryFlag:1;
    unsigned int waterLevel:15;
    unsigned int flags:4;
    unsigned int groundTextureType:4; // 24/32 bits belegt
    uint8_t textureDetails;           // neuer Datentyp -&gt; wird nicht in den uint geschrieben
    unsigned int cliffTextureType:4;
    unsigned int layerHeight:4;
};
</code></pre>
<p>Versuch mal das:</p>
<pre><code class="language-cpp">struct TilepointData
{
    uint16_t groundHeight;
    unsigned int boundaryFlag:1;
    unsigned int waterLevel:15;
    unsigned int flags:4;
    unsigned int groundTextureType:4;
    unsigned int cliffTextureType:4;
    unsigned int layerHeight:4;
    uint8_t textureDetails;
};

sizeof(struct TilepointData)
</code></pre>
</blockquote>
<p>Nette Idee.<br />
Und dann gleich noch das</p>
<pre><code class="language-cpp">struct TilepointData
{
    unsigned int boundaryFlag:1;
    unsigned int waterLevel:15;
    unsigned int flags:4;
    unsigned int groundTextureType:4;
    unsigned int cliffTextureType:4;
    unsigned int layerHeight:4;
    uint16_t groundHeight;
    uint8_t textureDetails;
};

sizeof(struct TilepointData)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1862092</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862092</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 27 Feb 2010 15:27:41 GMT</pubDate></item><item><title><![CDATA[Reply to sizeof auf bit fields on Sat, 27 Feb 2010 15:34:20 GMT]]></title><description><![CDATA[<p>Barade schrieb:</p>
<blockquote>
<p>Des Weiteren wollte ich allgemein mal fragen, ob man bit fields eher meiden sollte. Im obrigen Fall lohnt es sich für mich, da viele Werter kleiner als 1 Byte sind.</p>
</blockquote>
<p>Normalerweise erkauft man sich mit dem Packen der Daten meßbare bis störende Laufzeiteinbußen. Ich kenne nur wenige Ausnahmen, wie <a href="http://uo.stratics.com/heptazane/fileformats.shtml#2.0" rel="nofollow">http://uo.stratics.com/heptazane/fileformats.shtml#2.0</a> , wo ich den Entwicklern glaube, daß sie nachgemessen haben. Aber dort ging es wohl darum, möglichst viele der Daten überhaupt ind RAM zu kriegen, für einen gesparten Plattenzugriff kann man viele tausend bitshifts opfern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1862095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1862095</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 27 Feb 2010 15:34:20 GMT</pubDate></item></channel></rss>