<?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[NULL enthaltende Char* kopieren]]></title><description><![CDATA[<p>Guten Abend liebe Community,</p>
<p>ich habe das kleine Problem dass ich eine Binärdatei<br />
schreiben muss - Wie das öffnen und beschreiben eines binären Filestreams funktioniert ist mir bekannt.</p>
<p>Ich verwende einen Buffer der in x Runden immer mit y Byte erweitert werden soll, das Problem ist, dass in diesen Buffer auch binäre Nullen kopiert werden sollen.</p>
<pre><code class="language-cpp">char* buffer = new char[n];
char* abc = new char[y];

for(int i = 0; i &lt; x; i++){
    abc = FUNKTION();
    strcat(buffer, abc);
}

//Schreibe den Buffer in Datei
</code></pre>
<p>Da abc NULL-Terminatoren als Zeichen enthalten kann kann ich strcat nicht verwenden, da diese Funktion an einem solchen Zeichen angekommen die Arbeit abbricht.</p>
<p>Ich wäre für jede Hilfe dankbar <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>
<p>MfG Xeno</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/304465/null-enthaltende-char-kopieren</link><generator>RSS for Node</generator><lastBuildDate>Sun, 09 Aug 2026 09:53:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/304465.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Jun 2012 20:56:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 20:56:27 GMT]]></title><description><![CDATA[<p>Guten Abend liebe Community,</p>
<p>ich habe das kleine Problem dass ich eine Binärdatei<br />
schreiben muss - Wie das öffnen und beschreiben eines binären Filestreams funktioniert ist mir bekannt.</p>
<p>Ich verwende einen Buffer der in x Runden immer mit y Byte erweitert werden soll, das Problem ist, dass in diesen Buffer auch binäre Nullen kopiert werden sollen.</p>
<pre><code class="language-cpp">char* buffer = new char[n];
char* abc = new char[y];

for(int i = 0; i &lt; x; i++){
    abc = FUNKTION();
    strcat(buffer, abc);
}

//Schreibe den Buffer in Datei
</code></pre>
<p>Da abc NULL-Terminatoren als Zeichen enthalten kann kann ich strcat nicht verwenden, da diese Funktion an einem solchen Zeichen angekommen die Arbeit abbricht.</p>
<p>Ich wäre für jede Hilfe dankbar <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>
<p>MfG Xeno</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220427</guid><dc:creator><![CDATA[Xenogenesis]]></dc:creator><pubDate>Wed, 06 Jun 2012 20:56:27 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:02:52 GMT]]></title><description><![CDATA[<p>Was spricht gegen ein paar geile STL-Container?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220430</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:02:52 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:04:28 GMT]]></title><description><![CDATA[<p>Aua, das ist ja C mit new. Und warum nutzt du C-String Funktionen, wenn du gar nicht mit Strings arbeitest sondern mit Binärdaten?<br />
Bist du zudem sicher, dass das so soll? Denn bei deinem Code ist z.B. der Speicher auf den abc zeigt verloren, der wird doch nie freigegeben..<br />
Guck dir mal std::vector und Iteratoren an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220431</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:04:28 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:05:09 GMT]]></title><description><![CDATA[<p>Hacker schrieb:</p>
<blockquote>
<p>Was spricht gegen ein paar geile STL-Container?</p>
</blockquote>
<p>&quot;geil&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220433</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220433</guid><dc:creator><![CDATA[Gegensprechanlage]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:05:09 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:08:30 GMT]]></title><description><![CDATA[<p>Gegensprechanlage schrieb:</p>
<blockquote>
<p>Hacker schrieb:</p>
<blockquote>
<p>Was spricht gegen ein paar geile STL-Container?</p>
</blockquote>
<p>&quot;geil&quot;</p>
</blockquote>
<p>Mööp Mööp, STL rockt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /><br />
Oder das ist Geschmackssache - ich find auch nicht alles gut.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220436</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220436</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:08:30 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:13:18 GMT]]></title><description><![CDATA[<p>Hmm über einen Vector hatte ich nachgedacht, aber ich weiß nicht wie man den Inhalt in eine Datei schreiben könnte...</p>
<p>Das ganze soll die Endstufe einer Verschlüsselung werden.<br />
Die einzelnen Blöcke (immer multiple von 64-Bit) sollen aneinander gehängt und weggeschrieben werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220439</guid><dc:creator><![CDATA[Xenogenesis]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:13:18 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:15:02 GMT]]></title><description><![CDATA[<p>Xenogenesis schrieb:</p>
<blockquote>
<p>Hmm über einen Vector hatte ich nachgedacht, aber ich weiß nicht wie man den Inhalt in eine Datei schreiben könnte...</p>
</blockquote>
<p>Mit &amp;v[0] oder v.data()? Welchen Algorithmus implementierste denn? AES?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220440</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220440</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:15:02 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:17:54 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/25760">@cooky451</a></p>
<p>*KMT<br />
AUTSCH ok da hätte ich wirklich dran denken sollen^^<br />
Danke für das Öffnen meines geistigen Auges <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="😃"
    /></p>
<p>Ne nicht AES, ist eine Eigenentwicklung die ich seit fast einem Jahr plane und nun endlich Implementiere</p>
<p>Vielen Dank euch allen <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2220442</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220442</guid><dc:creator><![CDATA[Xenogenesis]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:17:54 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:25:19 GMT]]></title><description><![CDATA[<p>Xenogenesis schrieb:</p>
<blockquote>
<p>Ne nicht AES, ist eine Eigenentwicklung die ich seit fast einem Jahr plane und nun endlich Implementiere</p>
</blockquote>
<p>Interessant. Ich hoffe du weist entweder was du da tust (irgendwie bezweifel ich das :)), oder du willst den nicht in irgendetwas Sicherheitsrelevantem einsetzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220446</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:25:19 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:43:13 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Xenogenesis schrieb:</p>
<blockquote>
<p>Hmm über einen Vector hatte ich nachgedacht, aber ich weiß nicht wie man den Inhalt in eine Datei schreiben könnte...</p>
</blockquote>
<p>Mit &amp;v[0] oder v.<strong>data()</strong>?</p>
</blockquote>
<p>Bitte was? C++11? Oder seit wann hat std::vector eine solche Member-Funktion?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220450</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:43:13 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:46:56 GMT]]></title><description><![CDATA[<p>Hacker schrieb:</p>
<blockquote>
<p>C++11?</p>
</blockquote>
<p>Wie man auch in jeder Referenz nachgucken könnte..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220453</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:46:56 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 21:47:10 GMT]]></title><description><![CDATA[<p>Hacker schrieb:</p>
<blockquote>
<p>cooky451 schrieb:</p>
<blockquote>
<p>Xenogenesis schrieb:</p>
<blockquote>
<p>Hmm über einen Vector hatte ich nachgedacht, aber ich weiß nicht wie man den Inhalt in eine Datei schreiben könnte...</p>
</blockquote>
<p>Mit &amp;v[0] oder v.<strong>data()</strong>?</p>
</blockquote>
<p>Bitte was? C++11? Oder seit wann hat std::vector eine solche Member-Funktion?</p>
</blockquote>
<p>c++11</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220454</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Wed, 06 Jun 2012 21:47:10 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Wed, 06 Jun 2012 22:32:38 GMT]]></title><description><![CDATA[<p>@Xenogenesis<br />
std::vector&lt;char&gt; wie schon vorgeschlagen wurde ist sicher die bessere Wahl.</p>
<p>Ansonsten... was spricht gegen memcpy() und selber mitzählen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220462</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220462</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 06 Jun 2012 22:32:38 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Thu, 07 Jun 2012 07:51:44 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>Hacker schrieb:</p>
<blockquote>
<p>cooky451 schrieb:</p>
<blockquote>
<p>Xenogenesis schrieb:</p>
<blockquote>
<p>Hmm über einen Vector hatte ich nachgedacht, aber ich weiß nicht wie man den Inhalt in eine Datei schreiben könnte...</p>
</blockquote>
<p>Mit &amp;v[0] oder v.<strong>data()</strong>?</p>
</blockquote>
<p>Bitte was? C++11? Oder seit wann hat std::vector eine solche Member-Funktion?</p>
</blockquote>
<p>c++11</p>
</blockquote>
<p>cooky451 schrieb:</p>
<blockquote>
<p>Hacker schrieb:</p>
<blockquote>
<p>C++11?</p>
</blockquote>
<p>Wie man auch in jeder Referenz nachgucken könnte..</p>
</blockquote>
<p>Bei meiner Lieblingsreferenz gab es keine solche Member-Methode. Ich werde jetzt für die nächste Zeit wohl zu <a href="http://en.cppreference.com/w/cpp/container/vector/data" rel="nofollow">cppreference</a> wechseln müssen... ist aktueller.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220499</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 07 Jun 2012 07:51:44 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Sat, 09 Jun 2012 13:53:40 GMT]]></title><description><![CDATA[<p>Ja mit dem Vector funktioniert es dann auch <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="😃"
    /></p>
<p>Also sagen wir so, das ganze kommt in mehreren Applikationen und auch Projekten anderer zum Einsatz.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2221355</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2221355</guid><dc:creator><![CDATA[Xenogenesis]]></dc:creator><pubDate>Sat, 09 Jun 2012 13:53:40 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 09:31:24 GMT]]></title><description><![CDATA[<p>Was spricht gegen etwas wie AES, das auch sicher funktioniert?<br />
Wie ist dein Background in Zahlentheorie etc? Kannst du formell die Sicherheit deines Algorithmus beweisen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2222303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222303</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Tue, 12 Jun 2012 09:31:24 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 10:58:40 GMT]]></title><description><![CDATA[<p>Xenogenesis schrieb:</p>
<blockquote>
<pre><code class="language-cpp">char* buffer = new char[n];
char* abc = new char[y];

for(int i = 0; i &lt; x; i++){
    abc = FUNKTION();
    strcat(buffer, abc);
}
</code></pre>
</blockquote>
<p>Das ist echt wenig an Code. Wie sieht FUNCTION aus? Warum reservierst du per new[] Speicher und überschreibst den Zeiger später mit &quot;abc=&quot;? Warum überhaupt new[]?</p>
<p>Tipp: Wenn du glaubst, new[] und delete[] benutzen zu müssen, liegst du sehr wahrscheinlich falsch.</p>
<pre><code class="language-cpp">#include &lt;iterator&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;

template&lt;class OutputIterator&gt;
void func(OutputIterator oi)
{
  *oi++ = 'W';
  *oi++ = 'T';
  *oi++ = 'F';
  *oi++ = '?';
  *oi++ = '!';
}

int main()
{
  using namespace std;
  vector&lt;char&gt; buffer;
  for(int i = 0; i &lt; 5; i++) {
    func(back_inserter(buffer));
  }
  buffer.push_back('\0');
  cout &lt;&lt; &amp;buffer[0] &lt;&lt; endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2222329</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222329</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Tue, 12 Jun 2012 10:58:40 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 11:21:07 GMT]]></title><description><![CDATA[<p>Ethon schrieb:</p>
<blockquote>
<p>Was spricht gegen etwas wie AES, das auch sicher funktioniert?<br />
Wie ist dein Background in Zahlentheorie etc? Kannst du formell die Sicherheit deines Algorithmus beweisen?</p>
</blockquote>
<p>AES ist aber keine Vollbitverschlüsselung! <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2222335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222335</guid><dc:creator><![CDATA[_cu]]></dc:creator><pubDate>Tue, 12 Jun 2012 11:21:07 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 11:22:26 GMT]]></title><description><![CDATA[<p>Xenogenesis schrieb:</p>
<blockquote>
<pre><code class="language-cpp">char* buffer = new char[n];
</code></pre>
</blockquote>
<p>hustbaer schrieb:</p>
<blockquote>
<p>std::vector&lt;char&gt; wie schon vorgeschlagen wurde ist sicher die bessere Wahl.</p>
</blockquote>
<p>Ich will nicht kleinlich sein. Aber sollten binäre Daten nicht in <code>unsigned char</code> s dargestellt werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2222336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222336</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Tue, 12 Jun 2012 11:22:26 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 11:24:58 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Ich will nicht kleinlich sein. Aber sollten binäre Daten nicht in <code>unsigned char</code> s dargestellt werden?</p>
</blockquote>
<p>Sollten - ist aber ziemlich unüblich. Siehe z.B. ifstream::read, memcpy, etc.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2222337</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222337</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Tue, 12 Jun 2012 11:24:58 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 11:33:44 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Ich will nicht kleinlich sein. Aber sollten binäre Daten nicht in <code>unsigned char</code> s dargestellt werden?</p>
</blockquote>
<p>Warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2222338</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222338</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Tue, 12 Jun 2012 11:33:44 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 11:50:12 GMT]]></title><description><![CDATA[<p>_cu schrieb:</p>
<blockquote>
<p>AES ist aber keine Vollbitverschlüsselung! <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>
</blockquote>
<p>Du meinst sowas hier: <a href="http://www.kryptochef.de/" rel="nofollow">http://www.kryptochef.de/</a> ? lol</p>
<p>Ja, irgendwie ist die URL zensiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2222340</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222340</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Tue, 12 Jun 2012 11:50:12 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 11:54:56 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Ich will nicht kleinlich sein. Aber sollten binäre Daten nicht in <code>unsigned char</code> s dargestellt werden?</p>
</blockquote>
<p>Jepp, wenn ich binär I/O mache, dann verwende ich irgendwo auch unsigned char und irgendwoanders wird ge <code>reinterpret_cast</code> et. Ich verlass mich einfach darauf, dass das alles klappt und dass, falls die Maschine negative Ganzzahlen <em>nicht</em> per 2er-Komplement darstellt, <code>char</code> wenigstens vorzeichenlos ist, damit all die Bitmuster legal und einen einzigartigen char-Wert ergeben (also ohne die Problematik +/-0). Ich glaube nicht, dass eine solche Garantie direkt im C++ Standard gemacht wird, aber ich kann mir nicht vorstellen, wie man sonst vernünftig per char arbeiten können sollte, wenn man sich nicht mindestens auf eins von beiden (2er-komplement und/oder char ist vorzeichenlos) verlassen kann. Vielleicht folgt diese Garantie auch indirekt aus anderen Bedingungen ... denn es gibt z.b. die Garantie, dass ich einen POD so kopieren kann:</p>
<pre><code class="language-cpp">POD x = ...;
POD y;
{
  char const* p = reinterpret_cast&lt;char*&gt;(&amp;x);
  char      * q = reinterpret_cast&lt;char*&gt;(&amp;y);
  for (int i=0; i&lt;sizeof(y); ++i) {
    q[i] = p[i];
  }
}
</code></pre>
<p>und ich sehe nicht, wie das vernünftig funktionieren sollte, falls char sowohl vorzeichenbehaftet als auch so etwas wie sign+magnitude oder 1er-komplement verwendet. Da würde ja irgendwie Information verloren gehen, weil zwei verschiedene Bitmuster für die Null verwendet werden, also einmal +0 und einmal -0.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2222341</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222341</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Tue, 12 Jun 2012 11:54:56 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 12:20:52 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>Da würde ja irgendwie Information verloren gehen, weil zwei verschiedene Bitmuster für die Null verwendet werden, also einmal +0 und einmal -0.</p>
</blockquote>
<p>Solange die Repräsentation des Wertes beim Kopieren erhalten bleibt, sehe ich kein Problem? Wie ist das nochmal bei Gleitkommazahlen, eine negative 0 bleibt dort doch auch beim Kopieren erhalten, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2222352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222352</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 12 Jun 2012 12:20:52 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 12:25:55 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Solange die Repräsentation des Wertes beim Kopieren erhalten bleibt, sehe ich kein Problem</p>
</blockquote>
<p>Wo wird das garantiert, dass das so ist? Ich habe da tatsächlich mal nach gesucht, bin aber nicht fündig geworden ...</p>
<p>camper schrieb:</p>
<blockquote>
<p>Wie ist das nochmal bei Gleitkommazahlen, eine negative 0 bleibt dort doch auch beim Kopieren erhalten, oder?</p>
</blockquote>
<p>Wahrscheinlich. Nichts genaues, weiß ich nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2222355</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222355</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Tue, 12 Jun 2012 12:25:55 GMT</pubDate></item><item><title><![CDATA[Reply to NULL enthaltende Char* kopieren on Tue, 12 Jun 2012 12:39:17 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>camper schrieb:</p>
<blockquote>
<p>Solange die Repräsentation des Wertes beim Kopieren erhalten bleibt, sehe ich kein Problem</p>
</blockquote>
<p>Wo wird das garantiert, dass das so ist? Ich habe da tatsächlich mal nach gesucht, bin aber nicht fündig geworden ...</p>
</blockquote>
<p>Ich glaube die Frage ist auch falsch gestellt (und der Vegleich mit Gleitkommazahlen wahrscheinlich irrführend).</p>
<p>Wir haben:</p>
<blockquote>
<p>3.9.1 Fundamental types [basic.fundamental]<br />
1 Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic<br />
character set. If a character from this set is stored in a character object, the integral value of that character<br />
object is equal to the value of the single character literal form of that character. It is implementation-defined<br />
whether a char object can hold negative values. Characters can be explicitly declared unsigned or signed.<br />
Plain char, signed char, and unsigned char are three distinct types. A char, a signed char, and an<br />
unsigned char occupy the same amount of storage and have the same alignment requirements (3.11); that<br />
is, they have the same object representation. For character types, all bits of the object representation participate<br />
in the value representation. For unsigned character types, all possible bit patterns of the value<br />
representation represent numbers. These requirements do not hold for other types. In any particular implementation,<br />
a plain char object can take on either the same values as a signed char or an unsigned char;<br />
which one is implementation-defined.</p>
</blockquote>
<p>Das problematische Bitmuster 10000000 (bzw. entsprechnd länger) muss gar keine <em>Zahl</em> darstellen, unabhängig davon muss es aber ein gültiger <em>Wert</em> (non-trapping NaN oder so) sein. Zu sagen das wäre eine negative Null ist ggf. sowieso irreführend, dann der beobachtete Zahlenwert ist ohnehin erst das, was nach Konvertierung in int (o.ä.) antsteht; einfach deshalb, weil bei fast allen anwendbaren Operatoren erst einmal eine integrale Promotion ansteht.</p>
<blockquote>
<p>3.9 Types [basic.types]<br />
...<br />
2 For any object (other than a base-class subobject) of trivially copyable type T, whether or not the object<br />
holds a valid value of type T, the underlying bytes (1.7) making up the object can be copied into an array<br />
of char or unsigned char.40 If the content of the array of char or unsigned char is copied back into the<br />
object, the object shall subsequently hold its original value.</p>
</blockquote>
<p>Im Beispiel wir memcpy verwendet, allerdings eben nur als Beispiel. Soweit mir bewusst, definiert der Standard nicht ausdrücklich, was Kopieren hier genau bedeuten soll, mir scheint aber, dass eine einfache Zuweisung da mit eingeschlossen sein soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2222362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2222362</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 12 Jun 2012 12:39:17 GMT</pubDate></item></channel></rss>