<?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[In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname)]]></title><description><![CDATA[<p>Ich will ein kleines Tool schreiben, das in einem C++-Quelltext alle Typen erkennt. (Ich weiss, dass das nicht so einfach ist und es muss auch nicht perfekt sein.)</p>
<p>Meine Idee ist, dass wenn zwei Identifiers nebeneinander stehen, dass das dann eine Variablendeklaration sein muss und das erste ein Typ ist und das zweite der Variablenname.</p>
<pre><code class="language-cpp">Typ variable
Typ funktionsname
</code></pre>
<p>Dann kommt natürlich hinzu, dass nach class/struct immer ein Typ folgt.</p>
<pre><code class="language-cpp">struct Typ
class Typ
</code></pre>
<p>Sind das alle Fälle, oder habe ich da ein paar Spezialfälle vergessen, in denen das nicht so ist (Makros aussen vor gelassen)?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/323179/in-c-identifiers-klassifizieren-typ-variablenname</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 09:14:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/323179.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 20 Jan 2014 15:59:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 15:59:43 GMT]]></title><description><![CDATA[<p>Ich will ein kleines Tool schreiben, das in einem C++-Quelltext alle Typen erkennt. (Ich weiss, dass das nicht so einfach ist und es muss auch nicht perfekt sein.)</p>
<p>Meine Idee ist, dass wenn zwei Identifiers nebeneinander stehen, dass das dann eine Variablendeklaration sein muss und das erste ein Typ ist und das zweite der Variablenname.</p>
<pre><code class="language-cpp">Typ variable
Typ funktionsname
</code></pre>
<p>Dann kommt natürlich hinzu, dass nach class/struct immer ein Typ folgt.</p>
<pre><code class="language-cpp">struct Typ
class Typ
</code></pre>
<p>Sind das alle Fälle, oder habe ich da ein paar Spezialfälle vergessen, in denen das nicht so ist (Makros aussen vor gelassen)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378531</guid><dc:creator><![CDATA[keincompilerbauer]]></dc:creator><pubDate>Mon, 20 Jan 2014 15:59:43 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 16:10:41 GMT]]></title><description><![CDATA[<p>const int i;<br />
int* j;<br />
int&amp; k;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378534</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 20 Jan 2014 16:10:41 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 16:13:52 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>const int i;</p>
</blockquote>
<p>Das geht, Schlüsselwörter kann ich erkennen.</p>
<blockquote>
<p>int* j;<br />
int&amp; k;</p>
</blockquote>
<p>Stimmt, * und &amp; dürfen beliebig gemischt dazwischen stehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378537</guid><dc:creator><![CDATA[keincompilerbauer]]></dc:creator><pubDate>Mon, 20 Jan 2014 16:13:52 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 16:24:35 GMT]]></title><description><![CDATA[<p><a href="http://clang.llvm.org/doxygen/group__CINDEX.html" rel="nofollow">http://clang.llvm.org/doxygen/group__CINDEX.html</a> <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/2378539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378539</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Mon, 20 Jan 2014 16:24:35 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 16:28:50 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int i,j;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2378541</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378541</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Mon, 20 Jan 2014 16:28:50 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 17:27:18 GMT]]></title><description><![CDATA[<p>keincompilerbauer schrieb:</p>
<blockquote>
<blockquote>
<p>int* j;<br />
int&amp; k;</p>
</blockquote>
<p>Stimmt, * und &amp; dürfen beliebig gemischt dazwischen stehen.</p>
</blockquote>
<pre><code class="language-cpp">// 1.
typedef int A;
A * B;  // Deklaration

// 2.
int A, B;
A * B;  // Ausdruck
</code></pre>
<p>C++ ist voll von solchen Mehrdeutigkeiten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378563</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 20 Jan 2014 17:27:18 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 17:56:11 GMT]]></title><description><![CDATA[<pre><code>struct { ... } var;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2378573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378573</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Mon, 20 Jan 2014 17:56:11 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 18:15:09 GMT]]></title><description><![CDATA[<p>keincompilerbauer schrieb:</p>
<blockquote>
<p>Dann kommt natürlich hinzu, dass nach class/struct immer ein Typ folgt.</p>
<pre><code class="language-cpp">struct Typ
class Typ
</code></pre>
</blockquote>
<p>wohl eher aus c zeiten aber ist in c++ afaik auch erlaubt:</p>
<pre><code>typedef struct
{
    // ...
} Foo;

typedef struct
{
    // ...
} * Bar;
</code></pre>
<p>natürlich dann auch typendeduktion:</p>
<pre><code>auto Foo = 5;
decltype(Foo) Bar;
auto Baz = [](){};
</code></pre>
<p>und natürlich funktions- und methodenzeiger (bin mir nicht schlüssig ob das schon abgedeckt ist bislang):</p>
<pre><code>int (*Foo)(int);
int (MyClass::*Bar)(int) const;
</code></pre>
<p>unbenannte typen:</p>
<pre><code>enum
{
    Value = 42
};

class
{
    int a;
} Foo;

union
{
    int a;
    int b;
} Bar;
</code></pre>
<p>mehrfachdeklarationen:</p>
<pre><code>int a, * b;
int const* c, d;
</code></pre>
<p>edit:</p>
<p>keincompilerbauer schrieb:</p>
<blockquote>
<p>Meine Idee ist, dass wenn zwei Identifiers nebeneinander stehen, dass das dann eine Variablendeklaration sein muss und das erste ein Typ ist und das zweite der Variablenname.</p>
</blockquote>
<p>bin mir nicht sicher ob das hier abgedeckt ist:</p>
<pre><code>int Foo(); // Funktionsdeklaration
int Bar(1); // Instanziierung
</code></pre>
<p>oder templates:</p>
<pre><code>template&lt;typename T = int&gt;
struct MyClass1
{
};
MyClass1&lt;&gt; Foo;
MyClass&lt;bool&gt; Bar;

template&lt;int I&gt;
struct MyClass2
{
};
MyClass2&lt;42&gt; Baz;
</code></pre>
<pre><code>template&lt;class T&gt;
struct Foo
{
};
template&lt;template&lt;class&gt; class T&gt;
struct Bar
{
};
Bar&lt;Foo&gt; Baz;
</code></pre>
<pre><code>struct Bar
{
	typedef int A;
};
struct Baz
{
	typedef char A;
};
template&lt;typename T&gt;
struct Foo
{
	typedef typename T::A B;
};
Foo&lt;Bar&gt;::B C;
</code></pre>
<p>edit:</p>
<pre><code>template&lt;class T, int&gt;
struct Bar
{
	typedef char Type;
};
template&lt;int V&gt;
struct Bar&lt;int, V&gt;
{
	typedef void Type;
};
template&lt;template&lt;class, int&gt; class T = Bar&gt;
struct Foo : T&lt;int, 42&gt;
{
	typedef T&lt;int, 42&gt; Base;
	typedef typename Base::Type Type;
};
Foo&lt;&gt;::Type const* const&amp; Baz = 0;
</code></pre>
<p>sorry, gerade so freude daran mir sinnlosen quatsch auszudenken, ich hör schon auf...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378574</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Mon, 20 Jan 2014 18:15:09 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 17:57:37 GMT]]></title><description><![CDATA[<p>Eben darum: libclang...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378575</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378575</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Mon, 20 Jan 2014 17:57:37 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 19:22:33 GMT]]></title><description><![CDATA[<p>Hi es kamen jetzt eine ganze Menge Beispiele, aber keiner hat Deine erste Regel verletzt. Allerdings mußt Du Deine Regel etwas anpassen. Das gilt nämlich nur für den Anfang eines Statements und natü+rlich nur dann, wenn der Präproessor schon seine Arbeit verichtet hat.</p>
<p>Also bei zwei Identifiers am Anfang eines Statements <strong>OHNE</strong> Operator dazwischen, also nur white Spaces, ist muß der erste eine Typ sein.</p>
<p>Allerdings dürftest Du damit nur die wenigsten Typen finden. Denn fast immer befindet sich noch ein Schlüssewort davor. Darüber hinaus gibt es ja auch Schlüsselworte, die Typen bezeichnen. Da Du sowieso alle Schlüsselworte kennen mußt, um nicht versehentlich ein Schlüsselwort als Bezeichner zu behandeln, kannst Du die wichtigsten natürlich auch gleich korrekt behandeln.</p>
<p>Da wären als erstes natürlich die eingebauten Typen:<br />
bool, char, int, float, double</p>
<p>Dann natürlich die Typmodifiers<br />
short, long, signed, unsigned, const</p>
<p>und zum schluß die zusammengestzen Typen:<br />
struct, union, class</p>
<p>ebenfalls nicht zu schwer sollte sein<br />
enum</p>
<p>Wichtig ist halt auch, daß Du erkennen können mußt, WO die Statements anfangen. Dazu suchst Du alle geschweiften Klammern und Strichpunkte, die NICHT in einem Kommentar, literal oder einem for-statement sind.</p>
<p>Jetzt habe ich genug geschrieben und ich habe bestimmt irgendwas vergessen. Wenn Du das immer noch machen willst, viel Spaß, ist bestimmt sehr interessant.</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378598</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Mon, 20 Jan 2014 19:22:33 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 19:53:12 GMT]]></title><description><![CDATA[<p>mgaeckler schrieb:</p>
<blockquote>
<p>Wichtig ist halt auch, daß Du erkennen können mußt, WO die Statements anfangen. Dazu suchst Du alle geschweiften Klammern und Strichpunkte, die NICHT in einem Kommentar, literal oder einem for-statement sind.</p>
</blockquote>
<p>Das mit dem Anfang eines Statements kannst Du vergessen. Wenn Du zwei Bezeichner nur mit white spaces getrennt im Quelltext findest, dann muß der erste ein Typ sein. egal wo auch immer er steht. Allerdings solltest Du dann auch unbedingt :: erkennen können, damit Du den Typ nicht unvollständig liest.</p>
<p>Wenn Operatoren dazwischen stehen, wird's kompliziert.</p>
<p>A * B;</p>
<p>kann eine Multiplikation oder eine Deklaration sein, wie schon ein anderer vorher geschrieben haben. Ich schreibe es nur der Vollständigkeit halber <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>mfg Martin<br />
<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="😉"
    /> Dies ist keine Doktorarbeit, daher mache ich's wie Gutenberg. Ich entschuldige mich schon mal beim Autor, des zitierten Textes, aber das Beispiel find ich zu gut.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378610</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Mon, 20 Jan 2014 19:53:12 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 19:59:09 GMT]]></title><description><![CDATA[<p>Das Problem haben sicher schon K&amp;R beim Entwurf des ersten C-Compilers bemerkt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378611</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 20 Jan 2014 19:59:09 GMT</pubDate></item><item><title><![CDATA[Reply to In C++ Identifiers klassifizieren (Typ&#x2F;Variablenname) on Mon, 20 Jan 2014 20:18:23 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Das Problem haben sicher schon K&amp;R beim Entwurf des ersten C-Compilers bemerkt.</p>
</blockquote>
<p>Erst nachdem sie typedef implementiert haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378618</guid><dc:creator><![CDATA[tübbedef]]></dc:creator><pubDate>Mon, 20 Jan 2014 20:18:23 GMT</pubDate></item></channel></rss>