<?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[double a -&amp;gt; char array[sizeof(double)] ???]]></title><description><![CDATA[<p>HI,<br />
Ich würde gerne eine Funktion schreiben, welche alle typen in ein char array schreiben kann. Für int ist es kein Problem, aber double macht Probleme =(.<br />
Kennt jemand eine gute Lösung ??<br />
Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/249028/double-a-gt-char-array-sizeof-double</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 16:29:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/249028.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Sep 2009 18:32:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 18:32:26 GMT]]></title><description><![CDATA[<p>HI,<br />
Ich würde gerne eine Funktion schreiben, welche alle typen in ein char array schreiben kann. Für int ist es kein Problem, aber double macht Probleme =(.<br />
Kennt jemand eine gute Lösung ??<br />
Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770499</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 18:32:26 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 18:48:20 GMT]]></title><description><![CDATA[<p>Zeig mal, was du da mit den int's machst.. Das kommt mir sehr supsekt vor.. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770519</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Tue, 01 Sep 2009 18:48:20 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 18:50:19 GMT]]></title><description><![CDATA[<p>Trau mich nicht. *ggg*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770521</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770521</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 18:50:19 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 18:51:23 GMT]]></title><description><![CDATA[<p>Grundsätzlich wieder mal die nervige Frage: Wozu brauchst du das? <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>
<p>(Sollte vor allem dazu dienen, dass du dir nicht irgendwelche Frickellösungen und -wege aneignest, nur weil dir keine Alternativen bekannt sind.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770523</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 01 Sep 2009 18:51:23 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 18:52:38 GMT]]></title><description><![CDATA[<p>Ich muß den int in ein char array schreiben. Eben jedes Byte für sich.<br />
Und dannach wieder rausschreiben in ein int.<br />
Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770525</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770525</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 18:52:38 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 18:54:32 GMT]]></title><description><![CDATA[<p>Ich habe eine write Funktion. Die schreibt in Dateien.<br />
Und die kriegt ein char *. Und da müssen jetzt die typen konvertiert werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770527</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 18:54:32 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 19:05:17 GMT]]></title><description><![CDATA[<p>Mach das lieber so:</p>
<pre><code class="language-cpp">#include &lt;sstream&gt;

std::stringstream s;
double a = 5.0;

s &lt;&lt; a;

write ( s.str().c_str() );
</code></pre>
<p><code>std::stringstream</code> konvertiert dir alle Typen, die du reinschiebst automatisch und dann holst du dir per <code>::str</code> einen <code>std::string</code> und dann per <code>::c_str()</code> eben ein char Array.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770539</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Tue, 01 Sep 2009 19:05:17 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 19:10:26 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/18422">@drakon</a><br />
Danke. Hab das schon ziemlich oft so gemacht, aber gerade bin ich nicht drauf gekommen.<br />
Wahnsinn.<br />
Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770542</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770542</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 19:10:26 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 19:59:09 GMT]]></title><description><![CDATA[<p>Mal auf die gefahr hin das ich gelüncht werde <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title="=)"
      alt="🙂"
    /><br />
Mir schwebt irgendwie sowas vor:</p>
<pre><code class="language-cpp">int x;          //Die zu konvertierende Zahl
char *x_ptr=reinterpret_cast&lt;char *&gt;(&amp;x); //Ein Pointer dessen adrese byteweise erhöht wird

for(unsigned int count=0;count &lt; sizeof(x) count++)
   *(x_ptr+count)
</code></pre>
<p>Geht aber noch nicht. Und ich weiß nicht so richtig warum<br />
Gruß</p>
<p>P.s.<br />
Bitte lünchen ersparen, bin nicht sadomistisch veranlagt *ggg*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770561</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770561</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 19:59:09 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 20:04:30 GMT]]></title><description><![CDATA[<p>Was passt dir denn an der oben genannten Methode nicht??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770562</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770562</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Tue, 01 Sep 2009 20:04:30 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 20:14:40 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/18422">@Drakon</a><br />
-Mir ist zu spät aufgefallen, dass ich in dem Codeabschnitt wo ich mich gerade befinde keinen speicher merh anfordern darf.<br />
Wenn isch std::stringstream auch richtig initialisiere, glaube ich trotzdem, dass<br />
die Methode c_str neuen braucht.<br />
-Des weitern benötige ich eine Binäre umrechnung.<br />
Bei deiner Methode bekomme ich<br />
x=100;<br />
char a[3];<br />
a[0]=1;<br />
a[1]=0;<br />
a[2]=0;<br />
Ich würde benötigen:<br />
100=0x64=0000 0000 0110 0100<br />
a[0]=0000<br />
a[1]=0000<br />
a[2]=0110<br />
a[3]=0100<br />
Wobei die Konvertierung ja einfach dein a c_string -'0' wäre.<br />
-Ich bin der überzeugung, dass wenn der cast nach char* läuft,<br />
das fast nicht effizienter gemacht werden kann</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770569</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770569</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 20:14:40 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 20:21:39 GMT]]></title><description><![CDATA[<p>Ich habs, lesen mit</p>
<pre><code class="language-cpp">(*(x_ptr+count)&amp;0x0FF);
</code></pre>
<p>geht dann<br />
Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770575</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770575</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 20:21:39 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 20:39:33 GMT]]></title><description><![CDATA[<p>AlexXXx schrieb:</p>
<blockquote>
<p>Ich habs, lesen mit</p>
<pre><code class="language-cpp">(*(x_ptr+count)&amp;0x0FF);
</code></pre>
<p>geht dann<br />
Gruß</p>
</blockquote>
<p>Besser wäre, von vornherein unsigned char zu verwenden.<br />
*(x_ptr+count)<br />
ist nicht falsch, nur hast du möglicherweise falsche Erwartungen.</p>
<p>memcpy gibt es auch noch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770584</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 01 Sep 2009 20:39:33 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 20:44:51 GMT]]></title><description><![CDATA[<p>Also so gehts ganz gut:</p>
<pre><code class="language-cpp">int x=-999999;

    char *x_ptr=reinterpret_cast&lt;char *&gt;(&amp;x);
    unsigned char ar[sizeof(x)];

    std::cout &lt;&lt;&quot;\nx &quot; &lt;&lt;x;

    for(unsigned int count=0;count&lt;sizeof(x);count++)
        ar[count]=(int)(*(x_ptr+count) &amp; 0x0FF);

    x=0;

    for(int count=sizeof(x)-1;count&gt;=0;count--)
     {
        x=x &lt;&lt; 8;    
        x|=ar[count];
     }
    std::cout &lt;&lt;&quot;\nx &quot; &lt;&lt;x;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1770587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770587</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 20:44:51 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 20:48:39 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6642">@camper</a><br />
Ja du hast Recht, memcpy wäre eine lösung.<br />
Würds gern so noch ein bisschen weiter versuchen zum üben.<br />
Was muß ich denn für double machen ??<br />
double nach unsigned long int casten und dann wie vorher ??<br />
Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770591</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 20:48:39 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 20:53:36 GMT]]></title><description><![CDATA[<p>AlexXXx schrieb:</p>
<blockquote>
<pre><code class="language-cpp">ar[count]=(int)(*(x_ptr+count) &amp; 0x0FF);
</code></pre>
</blockquote>
<p>Das funktioniert, macht aber nicht den Eindruck, als dir wirklich bewusst ist, was hier passiert. Der Cast und das &amp; 0xFF sind völlig überflüssig (naja, nicht ganz im Allgemeinen, im Extremfall ist allerdings auch dein Konstrukt nicht korrekt).<br />
Wieso nicht einfach x_ptr ebenfalls als unsigned char*?</p>
<p>Ich vermute mal, dass char bei dir vorzeichenbehaftet ist, und dann mitunter negative Zahlen entstehen, mit denen du nicht gerechnet hast?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770592</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770592</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 01 Sep 2009 20:53:36 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 21:07:17 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6642">@camper</a>,<br />
Doch mir ist schon klar was passiert.<br />
Dass es überflüssig ist merk ich jetzt auch. Aber wies so ist, man tastet sich an den code ran.<br />
Dass MSB Vorzeichen ist ist klar.<br />
count mit unsigned char aufrufen ist besser. Stimmt schon.<br />
Ändert aber nichts an den Werten im Speicher.</p>
<p>Wenn mir was unklar ist, freu ich miich wenn dus mir erklärst, glaube es abernicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title="=)"
      alt="🙂"
    /><br />
P.s.: char ist bei mir nicht mehr vorzeichen behaftet gewesen.<br />
0x0FF hab ich vergessen raus zu machen. Da hst du schon Recht.</p>
<p>Aber wie bekomme ich das mit gleitkomazahlen hin. Wei0t du was ??<br />
Fang jetzt bitte nicht an mit ich weiß nicht wie die aufgebaut sond oder sowas.<br />
Wenni ch was nicht weiß, frage ich. (Das ist glaub erstes Semester gewesen )</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770600</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770600</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 21:07:17 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 21:28:20 GMT]]></title><description><![CDATA[<p>So ists besser. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title="=)"
      alt="🙂"
    /></p>
<pre><code class="language-cpp">int x=-99;

    char *x_ptr=reinterpret_cast&lt;char *&gt;(&amp;x);
    unsigned char ar[sizeof(x)];

    std::cout &lt;&lt;&quot;\nx &quot; &lt;&lt;x;

    for(unsigned int count=0;count&lt;sizeof(x);count++)
        ar[count]=*(x_ptr+count) ;

    x=0;

    for(int count=sizeof(x)-1;count&gt;=0;count--)
     {
        x=x &lt;&lt; 8;
        x|=ar[count];
     }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1770607</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770607</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 21:28:20 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 21:55:15 GMT]]></title><description><![CDATA[<p>So gehts auch für double. Ist glaub gut so.</p>
<pre><code class="language-cpp">double x=0.999;

    char *x_ptr=reinterpret_cast&lt;char *&gt;(&amp;x);
    unsigned char ar[sizeof(x)];

    std::cout &lt;&lt;&quot;\nx &quot; &lt;&lt;x;

    for(unsigned int count=0;count&lt;sizeof(x);count++)
        ar[count]=*(x_ptr+count) ;

    x=0;

    for(int count=sizeof(x)-1;count&gt;=0;count--)
        *(x_ptr+count)|=ar[count];

    std::cout &lt;&lt;&quot;\nx &quot; &lt;&lt;x;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1770612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770612</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 21:55:15 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 22:15:45 GMT]]></title><description><![CDATA[<p>AlexXXx schrieb:</p>
<blockquote>
<pre><code class="language-cpp">int x=-99;

    char *x_ptr=reinterpret_cast&lt;char *&gt;(&amp;x);
    unsigned char ar[sizeof(x)];

    std::cout &lt;&lt;&quot;\nx &quot; &lt;&lt;x;

    for(unsigned int count=0;count&lt;sizeof(x);count++)
        ar[count]=*(x_ptr+count) ;

    x=0;

    for(int count=sizeof(x)-1;count&gt;=0;count--)
     {
        x=x &lt;&lt; 8;
        x|=ar[count];
     }
</code></pre>
</blockquote>
<p>Was soll'n das werden, wenn's fertig ist? Die Kodierung passt überhaupt nicht zur Dekorierung. Das ist sowas von un-portabel, dass es nicht mal auf ein und demselben Rechner funktionieren muss.</p>
<p>Das hier wäre wenigstens konsistent:</p>
<pre><code class="language-cpp">void ich_scheiss_auf_portabel__nach_mir_die_sintflut() {
  int foo = 23;
  char dings[sizeof(foo)];
  std::memcpy(dings,&amp;foo,sizeof(dings)); // foo --&gt; dings
  std::memcpy(&amp;foo,dings,sizeof(foo)  ); // dings --&gt; foo
}
</code></pre>
<p>Der Haken: Solltest Du dings in eine Datei schreiben und auf einem anderen Rechner einer anderen Gattung wieder lesen wollen, wird das eventuell wieder nicht funktionieren.</p>
<p>Wenn Du vorhast plattformunabhängige Binärdateien zu schreiben, solltest Du das anders machen. Zum Beispiel unsigned ints manuell durch Shiften und Maskieren in unsigned chars zerlegen und wieder zurück.</p>
<p>Es gibt da übrigends noch so eine &quot;Aliasing&quot;-Regel, die man mit reinterpret_cast leicht verletzen kann. In Deinem Fall geht das noch in Ordnung, da Zeiger auf char bzw unsigned char auf alles zeigen dürfen.</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770620</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770620</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Tue, 01 Sep 2009 22:15:45 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 23:15:08 GMT]]></title><description><![CDATA[<p>-Also wie man das mit memcpy macht ist mir auch klar.<br />
Das hat schon jemand vor dir empfohlen und ich halte es auch mit für die beste Lösung.<br />
-Aber ich will ja auch was lernen.<br />
-Wiso das auf einem Rechner schief gehen soll ist mir nicht klar.<br />
(Würd mich über eine erklärung freuen)(Ich glaub das im Übrigen auch nicht wenn dus nicht begründest)<br />
(Zumal das Programm getestet ist und bei mir sehr gut läuft).<br />
-Unportabel zu anderen rechnern Meinst du wegen Big und Littel Endian ??<br />
-Kannst du mir die Aliasing Regel erklären ?? Die kenne ich nicht.<br />
(Gehts darum, dass ich die Blockgröße verletze,<br />
wenn sizeof(ptr_type a) den datenblock auf den es zeigt nicht ohne Rest teilt ??)Wenn ja ists trivial<br />
(-Aliasing kenne ich nur aus Nachrichtentechnik)<br />
-Die neuste version des codes schaut bereits so aus:</p>
<p>AlexXXx schrieb:</p>
<blockquote>
<pre><code class="language-cpp">double x=0.999;

    char *x_ptr=reinterpret_cast&lt;char *&gt;(&amp;x);
    unsigned char ar[sizeof(x)];

    std::cout &lt;&lt;&quot;\nx &quot; &lt;&lt;x;

    for(unsigned int count=0;count&lt;sizeof(x);count++)
        ar[count]=*(x_ptr+count) ;

    x=0;

    for(int count=sizeof(x)-1;count&gt;=0;count--)
        *(x_ptr+count)|=ar[count];

    std::cout &lt;&lt;&quot;\nx &quot; &lt;&lt;x;
</code></pre>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1770632</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770632</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 23:15:08 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Tue, 01 Sep 2009 23:19:29 GMT]]></title><description><![CDATA[<p>Werdet ihr echt für eure Antworten bezahlt, oder gute deutsche Hilfsbereitschaft??<br />
*ggg*<br />
Würd mich interessieren.<br />
Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770635</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Tue, 01 Sep 2009 23:19:29 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Wed, 02 Sep 2009 06:23:06 GMT]]></title><description><![CDATA[<p>AlexXXx schrieb:</p>
<blockquote>
<p>-Wiso das auf einem Rechner schief gehen soll ist mir nicht klar.</p>
</blockquote>
<p>Du greifst auf einen int über einen char* zu. Hier spielt die Byte-Ordnung eine Rolle und wieviel Bits ein Byte besitzt. Die ist nicht auf jedem Rechner gleich. Dann setzt Du den int wieder aus bytes manuell zusammen über &lt;&lt; und + oder |. Dabei nimmst Du an, dass Bytes 8 Bits besitzen und ein int im Little-Endian Format abgelegt ist. Auf einer Big-Endian-Maschine oder auf einer, die zB 16Bit-Bytes benutzt, kommt bei Dir Murks raus.</p>
<p>AlexXXx schrieb:</p>
<blockquote>
<p>-Unportabel zu anderen rechnern Meinst du wegen Big und Littel Endian ??</p>
</blockquote>
<p>Ja, und auch, was die Größe von ints angeht (16 bit? 24 bit? 32 bit? 64 bit?...)</p>
<p>AlexXXx schrieb:</p>
<blockquote>
<p>-Kannst du mir die Aliasing Regel erklären ?? Die kenne ich nicht.<br />
(Gehts darum, dass ich die Blockgröße verletze,<br />
wenn sizeof(ptr_type a) den datenblock auf den es zeigt nicht ohne Rest teilt ??)Wenn ja ists trivial<br />
(-Aliasing kenne ich nur aus Nachrichtentechnik)</p>
</blockquote>
<p>GIYF, strict aliasing</p>
<p>AlexXXx schrieb:</p>
<blockquote>
<p>-Die neuste version des codes schaut bereits so aus:</p>
</blockquote>
<p>Pfui bah!<br />
- Du greifst über char* zu und speicherst in unsigned char <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /><br />
- Du gehst davon aus, dass wenn Du x=0 setzt, alle Bits 0 sind <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /><br />
- Du benutzt nicht std::memcpy <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
<p>AlexXXx schrieb:</p>
<blockquote>
<p>Werdet ihr echt für eure Antworten bezahlt, oder gute deutsche Hilfsbereitschaft??</p>
</blockquote>
<p>Bezahlt? Nein. Deswegen solltest Du darauf achten, dass Du nicht unnötig Kapazität an Hilfsbereitschaft aufbrauchst. Statt so viele Fragen zu stellen, kannst Du Dir auch einfach 2-3 schlaue Bücher besorgen, und Internetsuchmaschinen benutzen. Das mit den Büchern lohnt sich -- auch für Dich.</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770672</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Wed, 02 Sep 2009 06:23:06 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Wed, 02 Sep 2009 09:59:26 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/28181">@SebastianP</a><br />
-Zunächt mal danke für kompetente Antwort. Hat mir weiter geholfen.<br />
-memcpy benutze ich nicht, weil ich ganz zu anfang gschrieben habe, dass ich<br />
eigentlich eine Funktion aufrufen will. Also:</p>
<pre><code class="language-cpp">write(char *,int size,......)
</code></pre>
<p>wenn ich memcpy verwenden möchte, müßte ich ja</p>
<pre><code class="language-cpp">int x; //zu schreibende Wert
unsigned char *x_ptr[sizeof(x)];
memcpy(....);    //x nach x_ptr glaub es war (destination,target,size) bin zu faul nach zu schauen
write(x_ptr,sizeof(x),...);
</code></pre>
<p>schreiben.<br />
Mit der anderen Variante stell ichi mir das so vor:</p>
<pre><code class="language-cpp">int x;
unsigned char x_ptr=einterpret_cast&lt;unsigned char *&gt;(&amp;x); 
write(x_ptr,sizeof(x),...);
</code></pre>
<p>Wegen bücher. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title="=)"
      alt="🙂"
    /> &quot;auch&quot;. Also wenn ich Bücher lese, lerne ich eigentlich immer was dazu. Mach das eigentlich ganz gern. Mein C und C++ ist weit davon entfernt ausgereift zu sein, und das wird wahrscheinlich auch immer so bleiben.<br />
Bücher würdest du die auf deiner Homepage empfahlen denke ich??<br />
Hatte mit Büchern in C++ bis jetzt nur Pech.<br />
habe mir C++ von A bis Z gekauft <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /><br />
Und mein erstes war Praktische C++ Programmierung von O'Reilly.<br />
Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770771</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770771</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Wed, 02 Sep 2009 09:59:26 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Wed, 02 Sep 2009 10:01:51 GMT]]></title><description><![CDATA[<p>AlexXXx schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/28181">@SebastianP</a><br />
-Zunächt mal danke für kompetente Antwort. Hat mir weiter geholfen.<br />
-memcpy benutze ich nicht, weil ich ganz zu anfang gschrieben habe, dass ich<br />
eigentlich eine Funktion aufrufen will. Also:</p>
<pre><code class="language-cpp">write(char *,int size,......)
</code></pre>
<p>wenn ich memcpy verwenden möchte, müßte ich ja</p>
<pre><code class="language-cpp">int x; //zu schreibende Wert
unsigned char x_ptr[sizeof(x)];
memcpy(....);    //x nach x_ptr glaub es war (destination,target,size) bin zu faul nach zu schauen
write(x_ptr,sizeof(x),...);
</code></pre>
<p>schreiben.<br />
Mit der anderen Variante stell ichi mir das so vor:</p>
<pre><code class="language-cpp">int x;
unsigned char *x_ptr=einterpret_cast&lt;unsigned char *&gt;(&amp;x); 
write(x_ptr,sizeof(x),...);
</code></pre>
<p>Wegen bücher. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title="=)"
      alt="🙂"
    /> &quot;auch&quot;. Also wenn ich Bücher lese, lerne ich eigentlich immer was dazu. Mach das eigentlich ganz gern. Mein C und C++ ist weit davon entfernt ausgereift zu sein, und das wird wahrscheinlich auch immer so bleiben.<br />
Bücher würdest du die auf deiner Homepage empfahlen denke ich??<br />
Hatte mit Büchern in C++ bis jetzt nur Pech.<br />
habe mir C++ von A bis Z gekauft <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /><br />
Und mein erstes war Praktische C++ Programmierung von O'Reilly.<br />
Gruß</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1770772</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770772</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Wed, 02 Sep 2009 10:01:51 GMT</pubDate></item><item><title><![CDATA[Reply to double a -&amp;gt; char array[sizeof(double)] ??? on Wed, 02 Sep 2009 13:02:01 GMT]]></title><description><![CDATA[<p>Was mich noch interessiern würd wäre:</p>
<p>Sebastian schrieb:</p>
<blockquote>
<p>Ja, und auch, was die Größe von ints angeht (16 bit? 24 bit? 32 bit? 64 bit?...)</p>
</blockquote>
<p>Ich dachte dass egal auf welcher Maschine char jeden<br />
Typen (Also gleitkomma oder ganzzahl)<br />
Ohne Rest teilen müßte.<br />
Folglich dürfte das bei der letzten Lösung keine Rolle spielen.<br />
(Big und little Endian ist nach wie vor ein Problem. Aber für mich zunächst uninteressant.)<br />
Der &lt;&lt; akzeptiere ich als schrott.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1770891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1770891</guid><dc:creator><![CDATA[AlexXXx]]></dc:creator><pubDate>Wed, 02 Sep 2009 13:02:01 GMT</pubDate></item></channel></rss>