<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C++: Not possible to define global constants?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/39780/c-not-possible-to-define-global-constants</link><description> 
If in &amp;quot;normal&amp;quot; C, I define a global constant in one
module: 

 
const int iTabCount= 5;
 

 
 
and then use this constant in another module (module2.c) with
extern: 

 
extern const int iTabCount;
 

 
 
Then &amp;quot;normal&amp;quot; C will do this without any problems</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: C++: Not possible to define global constants?</title><link>https://community.arm.com/thread/80332?ContentTypeID=1</link><pubDate>Wed, 20 Jun 2012 00:52:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8644b88b-c4bf-4fc3-85d5-121ea40c9873</guid><dc:creator>nice day</dc:creator><description>&lt;p&gt;&lt;p&gt;
Ups - I am surprised. You are right - if I insert the&lt;/p&gt;

&lt;pre&gt;
extern const int iAnzParTab;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
into the header file (included into both modules), then all works
fine.&lt;/p&gt;

&lt;p&gt;
Thank&amp;#39;s a lot! (I tried it also with my table - I can also declare
the &amp;quot;unknown size&amp;quot; table in this header file, and then give the
specific size only in module2.cpp - that&amp;#39;s exactly what I
needed:)&lt;/p&gt;

&lt;pre&gt;
extern const TAB aTab[];
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++: Not possible to define global constants?</title><link>https://community.arm.com/thread/60835?ContentTypeID=1</link><pubDate>Tue, 19 Jun 2012 17:20:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3e6977e8-a227-4b4d-b2a4-f5795b07bc77</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
Your problem starts right here:&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;and then use this constant in another module (module2.c) with
extern:&lt;br /&gt;&lt;/i&gt;&lt;/p&gt;

&lt;pre&gt;
&lt;i&gt;extern const int iTabCount;&lt;/i&gt;
&lt;/pre&gt;

&lt;p&gt;
You should basically &lt;b&gt;never&lt;/b&gt; write &amp;quot;extern&amp;quot; in any *.c file.
Extern declarations belong into *.h files, which you then #include
into *.c files (and that includes the *.c file with the
definition).&lt;/p&gt;

&lt;pre&gt;
&lt;i&gt;warning #177-D: variable &amp;quot;iTabCount&amp;quot; was declared but never referenced&lt;/i&gt;
&lt;/pre&gt;

&lt;p&gt;
This would probably not have happened had you #included that *.h
file into the module defining the variable.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;I think this is some C++ compiler problem?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
No. It&amp;#39;s a problem with your assumption that C and C++ were
basically the same language, so you could just compile some arbitrary
piece of C as C++ and get away with it. Well, that hasn&amp;#39;t been the
case since basically day 1 of the existence of C++ as a practical
programming language. So, to be blunt: &lt;b&gt;C and C++ are different
languages, get used to it.&lt;/b&gt; And yes, the precise meaning of the
&amp;#39;const&amp;#39; qualifier is one of the key differences between them. C uses
it to signify write-protected variables, C++ for actual
constants.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>