<?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[static const und extern &amp;quot;C&amp;quot;]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe das Problem, dass ich in einem C++-Projekt einen extern &quot;C&quot; Header habe, der Prototypen von Funktionen hat und Arrays, die von extern &quot;C&quot;-Funktionen aufgerufen werden:</p>
<p>Map.h</p>
<pre><code class="language-cpp">#ifndef _MAP_H_
#define _MAP_H_

#ifdef  __cplusplus
extern &quot;C&quot; {
#endif

#define MELD_IN_NUM 18
#define MELD_OUT_NUM 144
#define PICT_IN_NUM 6
#define PICT_OUT_NUM 48

extern uint8 meld[MELD_IN_NUM];

[...]

void mapxyz();

#ifdef  __cplusplus
}
#endif

#endif // _MAP_H_
</code></pre>
<p>Die Funktion mapxyz() wird von einer &quot;extern &quot;C&quot;&quot;-Funktion aufgerufen, das ganze kompiliert aber mit einem C++-Compiler. Kann ich dann trotzdem statt #define MELD_IN_NUM 18 ein static const MELD_IN_NUM = 18 schreiben, wohlwissend dass das unter C keine echte Konstante ist und deswegen nicht für Array-Größen verwendet werden kann, oder wird alles im C++-Kontext kompiliert und nur das Name-Mangling für die Funktion(en) verhindert?</p>
<p>Danke f. alle Hinweise</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/308040/static-const-und-extern-quot-c-quot</link><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Aug 2026 05:58:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/308040.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 13 Sep 2012 07:25:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 07:25:05 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe das Problem, dass ich in einem C++-Projekt einen extern &quot;C&quot; Header habe, der Prototypen von Funktionen hat und Arrays, die von extern &quot;C&quot;-Funktionen aufgerufen werden:</p>
<p>Map.h</p>
<pre><code class="language-cpp">#ifndef _MAP_H_
#define _MAP_H_

#ifdef  __cplusplus
extern &quot;C&quot; {
#endif

#define MELD_IN_NUM 18
#define MELD_OUT_NUM 144
#define PICT_IN_NUM 6
#define PICT_OUT_NUM 48

extern uint8 meld[MELD_IN_NUM];

[...]

void mapxyz();

#ifdef  __cplusplus
}
#endif

#endif // _MAP_H_
</code></pre>
<p>Die Funktion mapxyz() wird von einer &quot;extern &quot;C&quot;&quot;-Funktion aufgerufen, das ganze kompiliert aber mit einem C++-Compiler. Kann ich dann trotzdem statt #define MELD_IN_NUM 18 ein static const MELD_IN_NUM = 18 schreiben, wohlwissend dass das unter C keine echte Konstante ist und deswegen nicht für Array-Größen verwendet werden kann, oder wird alles im C++-Kontext kompiliert und nur das Name-Mangling für die Funktion(en) verhindert?</p>
<p>Danke f. alle Hinweise</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2250833</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250833</guid><dc:creator><![CDATA[AlGaN]]></dc:creator><pubDate>Thu, 13 Sep 2012 07:25:05 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 08:05:48 GMT]]></title><description><![CDATA[<p>Warum willst du denn einen C++-kompatiblen C-Header so abändern, dass er von C-Compilern nicht mehr verstanden wird?</p>
<p>extern &quot;C&quot; bezieht sich <em>nur</em> auf die Bindung und dem, was dazugehört. Es veranlasst keinen C++ Compiler, sich wie ein C Compiler zu verhalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2250841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250841</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Thu, 13 Sep 2012 08:05:48 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 08:31:57 GMT]]></title><description><![CDATA[<p>Weil ich die Konstanten bzw. Array-Größen auch noch in anderen (C++-)Modulen brauche und da lieber static consts hätte statt #define's?</p>
<p>Es gibt eben Inkonsistenzen, wenn ich an einer Stelle #define's habe und an anderer Stelle (im C++-Kontext noch dazu in einem Namespace) static const Konstanten...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2250848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250848</guid><dc:creator><![CDATA[AlGaN]]></dc:creator><pubDate>Thu, 13 Sep 2012 08:31:57 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 09:25:39 GMT]]></title><description><![CDATA[<p>const funktioniert doch auch in C!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2250862</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250862</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 13 Sep 2012 09:25:39 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 09:30:47 GMT]]></title><description><![CDATA[<p>dot schrieb:</p>
<blockquote>
<p>const funktioniert doch auch in C!?</p>
</blockquote>
<p>Aber nicht als konstanter Ausdruck für die Arraydimension.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2250867</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250867</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Thu, 13 Sep 2012 09:30:47 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 09:33:16 GMT]]></title><description><![CDATA[<p>Stimmt, da war doch was (ich verwend einfach viel zu selten C). In dem Fall könntest du ein #ifdef __cplusplus machen, um die Dinger jeweils als const oder als #define zu definieren, oder den enum Hack verwenden...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2250868</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250868</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 13 Sep 2012 09:33:16 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 11:16:58 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<p>Aber nicht als konstanter Ausdruck für die Arraydimension.</p>
</blockquote>
<p>Muss die Arraydimension in C überhaupt konstant sein? Ich dachte dort gibt es VLA.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2250905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250905</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 13 Sep 2012 11:16:58 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 12:08:02 GMT]]></title><description><![CDATA[<p>VLA ist ein C99 Feature und funktioniert nur für lokale Arrays in Funktionen. Und wieso ein VLA machen, wenn die Größe doch konstant ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2250931</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250931</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 13 Sep 2012 12:08:02 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 18:56:25 GMT]]></title><description><![CDATA[<p>Reduzieren wir das Problem auf das Minimum.</p>
<p>AlGaN schrieb:</p>
<blockquote>
<pre><code class="language-cpp">extern uint8 meld[MELD_IN_NUM];
</code></pre>
</blockquote>
<p>Was spricht gegen?</p>
<pre><code class="language-cpp">extern uint8* meld;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2251081</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251081</guid><dc:creator><![CDATA[nurf]]></dc:creator><pubDate>Thu, 13 Sep 2012 18:56:25 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 18:58:14 GMT]]></title><description><![CDATA[<p>nurf schrieb:</p>
<blockquote>
<p>Reduzieren wir das Problem auf das Minimum.</p>
<p>AlGaN schrieb:</p>
<blockquote>
<pre><code class="language-cpp">extern uint8 meld[MELD_IN_NUM];
</code></pre>
</blockquote>
<p>Was spricht gegen?</p>
<pre><code class="language-cpp">extern uint8* meld;
</code></pre>
</blockquote>
<p>Was spricht gegen</p>
<pre><code class="language-cpp">extern uint8 meld[];
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2251082</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251082</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 13 Sep 2012 18:58:14 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 18:59:31 GMT]]></title><description><![CDATA[<p>nurf schrieb:</p>
<blockquote>
<p>Was spricht gegen?</p>
<pre><code class="language-cpp">extern uint8* meld;
</code></pre>
</blockquote>
<p>Dass es etwas völlig anderes ist und wohl kaum das Problem löst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2251083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251083</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 13 Sep 2012 18:59:31 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 19:19:23 GMT]]></title><description><![CDATA[<p>AlGaN schrieb:</p>
<blockquote>
<p>Kann ich dann trotzdem statt #define MELD_IN_NUM 18 ein static const MELD_IN_NUM = 18 schreiben, wohlwissend dass das unter C keine echte Konstante ist und deswegen nicht für Array-Größen verwendet werden kann, oder wird alles im C++-Kontext kompiliert und nur das Name-Mangling für die Funktion(en) verhindert?</p>
</blockquote>
<p>Na ich denke schon dass du das kannst. Probiers halt aus.<br />
Ich denke aber auch dass du die #defines auch einfach #defines bleiben lassen kannst, das Hinzufügen eines geeigneten Prefix zum Namen sollte vollkommen ausreichend sein - bzw. vielleicht noch die Namen etwas verständlicher machen, würde auch nicht schaden.<br />
Ich persönlich verwende einfach immer den Projektnamen als Prefix. Bzw. den Namespacenamen (was bei mir das selbe ist).</p>
<p>Also statt</p>
<pre><code class="language-cpp">namespace Foosel
{
static const short Blah = 123;
}
</code></pre>
<p>einfach</p>
<pre><code class="language-cpp">#define FOOSEL_BLAH ((short) 123)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2251091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251091</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 13 Sep 2012 19:19:23 GMT</pubDate></item><item><title><![CDATA[Reply to static const und extern &amp;quot;C&amp;quot; on Thu, 13 Sep 2012 19:40:49 GMT]]></title><description><![CDATA[<p>AlGaN schrieb:</p>
<blockquote>
<p>Es gibt eben Inkonsistenzen, wenn ich an einer Stelle #define's habe und an anderer Stelle (im C++-Kontext noch dazu in einem Namespace) static const Konstanten...</p>
</blockquote>
<p>Das eine ist halt C, das andere C++. Wie ich schon hab durchscheinen lassen, finde ich deine Idee nicht so toll wie du selbt. Ich würd's einfach so lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2251106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251106</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Thu, 13 Sep 2012 19:40:49 GMT</pubDate></item></channel></rss>