<?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[struct packen geht nicht.....]]></title><description><![CDATA[<p>hallo leute,<br />
ich habe folgendes problem:</p>
<p>ich habe einen struct für das fat12 datum- und zeitformat.<br />
die sind beide aber 4 statt 2 byte groß (sizeof())...<br />
wie kann ich die nun packen?<br />
#pragma und __attribute__ gehen beide irgendwie nicht.<br />
ich mache das ganze mit vs2005</p>
<pre><code class="language-cpp">//#pragma pack(1)   &lt;- geht nicht
struct FAT_time						/* Warning: this struct must be packed		 */
{
	unsigned two_secs : 5;			/* low 5 bits: 2-second increments			 */
	unsigned minutes : 6;			/* middle 6 bits: minutes					 */
	unsigned hours : 5;				/* high 5 bits: hours (0-23)				 */
}; // __attribute__ ((packed));    &lt;- geht nicht
</code></pre>
<p>danke im voraus<br />
Uni_Sol</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/158325/struct-packen-geht-nicht</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 19:25:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/158325.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Sep 2006 12:29:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 12:29:25 GMT]]></title><description><![CDATA[<p>hallo leute,<br />
ich habe folgendes problem:</p>
<p>ich habe einen struct für das fat12 datum- und zeitformat.<br />
die sind beide aber 4 statt 2 byte groß (sizeof())...<br />
wie kann ich die nun packen?<br />
#pragma und __attribute__ gehen beide irgendwie nicht.<br />
ich mache das ganze mit vs2005</p>
<pre><code class="language-cpp">//#pragma pack(1)   &lt;- geht nicht
struct FAT_time						/* Warning: this struct must be packed		 */
{
	unsigned two_secs : 5;			/* low 5 bits: 2-second increments			 */
	unsigned minutes : 6;			/* middle 6 bits: minutes					 */
	unsigned hours : 5;				/* high 5 bits: hours (0-23)				 */
}; // __attribute__ ((packed));    &lt;- geht nicht
</code></pre>
<p>danke im voraus<br />
Uni_Sol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130743</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130743</guid><dc:creator><![CDATA[bsunisol]]></dc:creator><pubDate>Mon, 04 Sep 2006 12:29:25 GMT</pubDate></item><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 12:53:26 GMT]]></title><description><![CDATA[<p>EDIT: * ignorance induced junk removed *</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130751</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130751</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 04 Sep 2006 12:53:26 GMT</pubDate></item><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 12:47:31 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>also ein struct mit 3 Elementen wirst Du nur seeehr schwer in 2 Bytes unterbekommen.</p>
</blockquote>
<p>Was spricht dagegen, 16 Bit in 2 Byte unterzubringen?</p>
<blockquote>
<p>BTW: &quot;unsigned was&quot; ? Ich bin mir gar nicht sicher, dass das C++-Syntax ist, was Du da anbietest ? (&quot; .. : 5 ...&quot; ?)</p>
</blockquote>
<p>Da das eine C-Struktur sein dürfte (Filesystem-Header), default-int, also ist &quot;unsigned&quot; hier &quot;unsigned int&quot;. Und imho ist das für C++ sogar immernoch gültig, da default-int nur bei Funktionsrückgabetypen verboten ist.</p>
<p>EDIT 2 (siehe unten):<br />
Das funktioniert übrigens unabhängig von pragma pack(1). sizeof ist immernoch 4, das dürfte am Alignment des Bitfields auf Integer (4 Byte) liegen. Wenn man sich die Struktur dann aber mal visualisiert liegen die Bits genau richtig.</p>
<pre><code class="language-cpp">FAT_time x = { 16 /* Bit 5 gesetzt */, 32 /* Bit 6 gesetzt */, 16 };
cout &lt;&lt; *reinterpret_cast&lt;int*&gt;(&amp;x) &lt;&lt; endl;
</code></pre>
<p>Ausgabe: 33808, binär 1000010000010000</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130755</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130755</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 04 Sep 2006 12:47:31 GMT</pubDate></item><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 12:44:26 GMT]]></title><description><![CDATA[<p>geht denn das hier?</p>
<pre><code class="language-cpp">//#pragma pack(1)   &lt;- geht nicht
struct FAT_time						/* Warning: this struct must be packed		 */
{
	unsigned short two_secs : 5;			/* low 5 bits: 2-second increments			 */
	unsigned short minutes : 6;			/* middle 6 bits: minutes					 */
	unsigned short hours : 5;				/* high 5 bits: hours (0-23)				 */
}; // __attribute__ ((packed));    &lt;- geht nicht
</code></pre>
<p>ich würde bei dem bitfield das problem nicht auf packen schieben, sondern aufs alignment.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130761</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 04 Sep 2006 12:44:26 GMT</pubDate></item><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 12:46:30 GMT]]></title><description><![CDATA[<p>In der Tat, funktioniert es auch ganz ohne pragma pack...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130762</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130762</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 04 Sep 2006 12:46:30 GMT</pubDate></item><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 12:53:46 GMT]]></title><description><![CDATA[<p>EDIT: * ignorance induced junk removed *</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130763</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 04 Sep 2006 12:53:46 GMT</pubDate></item><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 12:50:22 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>Nichts. Und ? Habe ich was Anderes behauptet ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Im Grunde ja, Du hast behauptet dass drei Elemente (5+6+5 Bit = 16 Bit) nicht in zwei Byte passen können <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
<p>LordJaxom schrieb:</p>
<blockquote>
<p>Ist mir schon klar, aber mit meiner Frage wollte ich bsunisol mal zum Nachdenken anregen, wieviel Platz denn wohl 3 int's brauchen könnten. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>siehe oben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130765</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 04 Sep 2006 12:50:22 GMT</pubDate></item><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 12:54:36 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>Ist mir schon klar, aber mit meiner Frage wollte ich bsunisol mal zum Nachdenken anregen, wieviel Platz denn wohl 3 int's brauchen könnten. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Offensichtlich 3*sizeof(int). Aber deine Unsicherheit bezüglich der Syntax (&quot;... : N;&quot;) hätte dich lieber mal zum Nachdenken anregen sollen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130769</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Mon, 04 Sep 2006 12:54:36 GMT</pubDate></item><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 13:01:32 GMT]]></title><description><![CDATA[<p>finix schrieb:</p>
<blockquote>
<p>...deine Unsicherheit bezüglich der Syntax (&quot;... : N;&quot;) hätte dich lieber mal zum Nachdenken anregen sollen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Hat es, hat es, keine Sorge. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Aber ehrlich gesagt: Dass das weder mir noch meinen 4 C(++)-erfahrenen Kollegen (alle schon mehrere Jahre im Geschäft) noch nie begegnet ist (und alle spontan sagten: &quot;Das kann gar nicht kompilieren&quot;), verwundert schon ein wenig.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130778</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130778</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 04 Sep 2006 13:01:32 GMT</pubDate></item><item><title><![CDATA[Reply to struct packen geht nicht..... on Mon, 04 Sep 2006 13:52:48 GMT]]></title><description><![CDATA[<p>nein es geht alles nicht.<br />
wenn ich datei dann mit einem hex editor öffne ist der struct größer als ich ihn haben will...</p>
<p>beispiel:</p>
<p>so müsste es aussehen:<br />
struct 1:</p>
<pre><code>4B 45 52 4E 45 4C 20 20 53 59 53 20 00 41 D8 6A
24 35 24 35 00 00 A0 AA DD 34 02 00 44 00 00 00
</code></pre>
<p>struct 2:</p>
<pre><code>4F 53 4C 44 52 20 20 20 20 20 20 20 00 0f DA 6A
24 35 24 35 00 00 A0 AA DD 34 02 00 44 00 00 00
</code></pre>
<p>aber meine sehen so aus:</p>
<pre><code>54 45 53 54 20 20 20 20 54 58 54 10 00 CD CD CD
3E 53 CD CD 24 35 CD CD 24 35 CD CD 00 00 CD CD
3E 53 CD CD 24 35 CD CD 19 00 CD CD 00 04 00 00
</code></pre>
<p>ich bin am verzweifeln.....</p>
<p>Uni_Sol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130812</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130812</guid><dc:creator><![CDATA[bsunisol]]></dc:creator><pubDate>Mon, 04 Sep 2006 13:52:48 GMT</pubDate></item></channel></rss>