<?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[C-Liste &#x2F; Problem mit Verkettung mittels Pointer]]></title><description><![CDATA[<p>Hallo liebes Forum,</p>
<p>Ich möchte in C eine Liste von &quot;Transitionen&quot; erzeugen, in der mittels Prozedur &quot;findLast&quot; (s.u.) das erste Listenelement != NULL gefunden werden soll (sofern vorhanden).</p>
<p>Beim Compilieren erhalte ich jedoch stets die Meldung</p>
<p>pointer.c:18: error: request for member `next' in something not a structure or union</p>
<p>wobei Zeile 18 die folgende der Prozedur &quot;findLast&quot; ist:</p>
<pre><code>kaese = &amp;(*kaese-&gt;next);
</code></pre>
<p>[Den u.a. Code habe ich auf das Wesentliche gekürzt, darum sollte man sich über Sinn oder Unsinn des Programmfragmentes keine Gedanken machen.]</p>
<p>Warum kann der Pointer &quot;kaese&quot; nicht auf das &quot;next&quot;-Listenelement zeigen??</p>
<p>Für eine Lösung wäre ich super dankbar! <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="🕶"
    /></p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;

typedef struct {
  char* state1;
  char* label;
  char* state2;
} TRANSITION;

typedef struct {
  TRANSITION transition;
  struct TRANSITIONSLIST* next;
} TRANSITIONSLIST;

void findLast (TRANSITIONSLIST** kaese) {
  while(*kaese != NULL) {
    kaese = &amp;(*kaese-&gt;next); /* Geht nicht?! */
  }
}

int main (int argc, char* argv[]) {

  TRANSITIONSLIST* kaese = NULL;
  findLast(&amp;kaese);
  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/138519/c-liste-problem-mit-verkettung-mittels-pointer</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 04:01:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/138519.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 27 Feb 2006 05:09:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C-Liste &#x2F; Problem mit Verkettung mittels Pointer on Mon, 27 Feb 2006 05:09:03 GMT]]></title><description><![CDATA[<p>Hallo liebes Forum,</p>
<p>Ich möchte in C eine Liste von &quot;Transitionen&quot; erzeugen, in der mittels Prozedur &quot;findLast&quot; (s.u.) das erste Listenelement != NULL gefunden werden soll (sofern vorhanden).</p>
<p>Beim Compilieren erhalte ich jedoch stets die Meldung</p>
<p>pointer.c:18: error: request for member `next' in something not a structure or union</p>
<p>wobei Zeile 18 die folgende der Prozedur &quot;findLast&quot; ist:</p>
<pre><code>kaese = &amp;(*kaese-&gt;next);
</code></pre>
<p>[Den u.a. Code habe ich auf das Wesentliche gekürzt, darum sollte man sich über Sinn oder Unsinn des Programmfragmentes keine Gedanken machen.]</p>
<p>Warum kann der Pointer &quot;kaese&quot; nicht auf das &quot;next&quot;-Listenelement zeigen??</p>
<p>Für eine Lösung wäre ich super dankbar! <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="🕶"
    /></p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;

typedef struct {
  char* state1;
  char* label;
  char* state2;
} TRANSITION;

typedef struct {
  TRANSITION transition;
  struct TRANSITIONSLIST* next;
} TRANSITIONSLIST;

void findLast (TRANSITIONSLIST** kaese) {
  while(*kaese != NULL) {
    kaese = &amp;(*kaese-&gt;next); /* Geht nicht?! */
  }
}

int main (int argc, char* argv[]) {

  TRANSITIONSLIST* kaese = NULL;
  findLast(&amp;kaese);
  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1003845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1003845</guid><dc:creator><![CDATA[Flachkoepper]]></dc:creator><pubDate>Mon, 27 Feb 2006 05:09:03 GMT</pubDate></item><item><title><![CDATA[Reply to C-Liste &#x2F; Problem mit Verkettung mittels Pointer on Mon, 27 Feb 2006 06:22:48 GMT]]></title><description><![CDATA[<p>zuviel *&amp;<br />
geht einfacher, event noch mal entsprechende dokus lesen</p>
<p>(ich geh davon aus das du dich in dem von dir weggekuerztem teil darum kuemmerst das next mit NULL initialisiert wird)</p>
<p>void findLast (TRANSITIONSLIST * kaese) {<br />
while(kaese != NULL) {<br />
kaese = kaese-&gt;next;<br />
}<br />
}</p>
<p>aufruf:</p>
<p>TRANSITIONSLIST * kaese = NULL;<br />
findLast(kaese);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1003850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1003850</guid><dc:creator><![CDATA[daHa]]></dc:creator><pubDate>Mon, 27 Feb 2006 06:22:48 GMT</pubDate></item><item><title><![CDATA[Reply to C-Liste &#x2F; Problem mit Verkettung mittels Pointer on Mon, 27 Feb 2006 07:23:59 GMT]]></title><description><![CDATA[<p>Hallo daHa,</p>
<p>Erstmal danke für die schnelle Antwort!!</p>
<p>Mit den verkürzten &amp; bzw * Symbolen klappt es, aber dann habe ich insbesondere bei dem ersten Listen-Element ein Call-By-Value statt Call-By-Reference.</p>
<p>Angenommen, ich möchte in der Prozedur &quot;findLast&quot; das erste Listenelement setzen, also schreibend auf die Liste zugreifen (nicht schön, aber ist eben nur ein Beispiel). Dann brauche ich die Referenz auf das erste Zeigerelement.</p>
<p>Wie sieht die Lösung aus, wenn der Prozedurkopf gleich bleiben soll?</p>
<p>Ich hoffe, mein etwas erweitertes Beispiel (Adressen hier als &quot;Hack&quot;) macht mein Problem klarer:</p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;

typedef struct {
  char* state1;
  char* label;
  char* state2;
} TRANSITION;

typedef struct {
  TRANSITION transition;
  struct TRANSITIONSLIST* next;
} TRANSITIONSLIST;

/* Call-By-Value (klappt, aber ist nicht das, was ich haben will) */

void findLast_cbv (TRANSITIONSLIST* kaese) {

  while(kaese != NULL) {
    kaese = (TRANSITIONSLIST*)(kaese -&gt; next);
  }

  kaese = (TRANSITIONSLIST*)1; /* Aenderung nur lokale Variable */
}

/* Call-By-Reference (das, was ich eigentlich haben moechte) */

void findLast_cbr (TRANSITIONSLIST** kaese) {

/* Warum geht das hier nicht?! Erzeugt:
   error: request for member `next' in something not a structure or union

  while(*kaese != NULL) {
    *kaese = (TRANSITIONSLIST*)(*kaese -&gt; next);
  }
*/

  *kaese = (TRANSITIONSLIST*)1; /* Aenderung glokale Variable */
}

int main (int argc, char* argv[]) {

  TRANSITIONSLIST* kaese = NULL;
  findLast_cbv(kaese);
  printf(&quot;%d\n&quot;,kaese); /* Ausgabe 0 */

  findLast_cbr(&amp;kaese);
  printf(&quot;%d\n&quot;,kaese); /* Ausgabe 1 */

  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1003867</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1003867</guid><dc:creator><![CDATA[Flachkoepper]]></dc:creator><pubDate>Mon, 27 Feb 2006 07:23:59 GMT</pubDate></item><item><title><![CDATA[Reply to C-Liste &#x2F; Problem mit Verkettung mittels Pointer on Mon, 27 Feb 2006 10:40:37 GMT]]></title><description><![CDATA[<p>void findLast_cbv (TRANSITIONSLIST* kaese) {</p>
<p>ist nicht call by value, das ist call by reference. es wird nur die adresse übergeben, nicht das objekt.</p>
<p>sowas</p>
<p>int **a;</p>
<p>ist nen pointer auf nen pointer. kann sinnvoll sein, aber in deinem fall nicht nötig.</p>
<p>wenn du &quot;echtes&quot; by reference im c++ stil haben willst, kannst du auch</p>
<p>void findLast_cbv (TRANSITIONSLIST&amp; kaese) {</p>
<p>schreiben. verhält sich in deinem fall dann aber gleich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1003960</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1003960</guid><dc:creator><![CDATA[gulp123]]></dc:creator><pubDate>Mon, 27 Feb 2006 10:40:37 GMT</pubDate></item><item><title><![CDATA[Reply to C-Liste &#x2F; Problem mit Verkettung mittels Pointer on Mon, 27 Feb 2006 10:47:18 GMT]]></title><description><![CDATA[<p>mal nen beispiel, wie verkettung funktioniert.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

struct Node
{
 int payload;
 Node *next;
}

void findLast(Node *node) // call by reference
{
 while(node != 0)
  node = node-&gt;next;
}

int main()
{
 Node c; c.payload = 3; c.next = 0;
 Node b; b.payload = 2; b.next = &amp;c;
 Node a; a.payload = 1; a.next = &amp;b;

 Node t = a;
 findLast(&amp;t);

 std::cout &lt;&lt; &quot;last node's payload = &quot; &lt;&lt; t.payload &lt;&lt; std::endl;

 return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1003963</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1003963</guid><dc:creator><![CDATA[gulp123]]></dc:creator><pubDate>Mon, 27 Feb 2006 10:47:18 GMT</pubDate></item><item><title><![CDATA[Reply to C-Liste &#x2F; Problem mit Verkettung mittels Pointer on Mon, 27 Feb 2006 11:13:51 GMT]]></title><description><![CDATA[<p>Flachkoepper, bitte arbeite noch mal ein oder zwei tutorials durch</p>
<p>und versuch dir selbst den unterschied von folgendem zu erklaehren</p>
<p>void foo( int x ) ;<br />
void foo( int &amp; x ) ;<br />
void foo( int * x ) ;</p>
<p>und</p>
<p>int x = 1;</p>
<p>int a = x;<br />
int &amp; b = x ;<br />
int * c = &amp;x;</p>
<p>und probier nach ein bissl herum, so ala</p>
<p>*c = 5;</p>
<p>b = 7;</p>
<p>usw</p>
<p>und schau dir jedesmal die werte an</p>
<p>ich denke das sollte dann einige fragen klaehren</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1003979</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1003979</guid><dc:creator><![CDATA[daHa]]></dc:creator><pubDate>Mon, 27 Feb 2006 11:13:51 GMT</pubDate></item></channel></rss>