<?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>const integral values across modules and ROM placement</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/29609/const-integral-values-across-modules-and-rom-placement</link><description> 
Hi, 

 
I have the following code: 

 
 file1.h 

 
extern const unsigned char c1;
 

 
 file1.c 

 
const unsigned char c1 = 25;
 

 
 file2.c 

 
const unsigned char c2 = c1 + 25;
 

 
According to the documentation 
 www.keil.com/.../armccref_ciabaidh</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: const integral values across modules and ROM placement</title><link>https://community.arm.com/thread/128008?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2013 12:38:55 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:45fd9fa5-26d4-4af2-99d9-2fccafb4af4d</guid><dc:creator>Gaseous Trousers</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;As far as expectations are concerned ...&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
And there is the problem. In the real world, it is not uncommon
for people within a group to have different expectations. For
example, one person might think another is pompous and pretentious
fool. Obviously, if they were to think that about me, they would
clearly be wrong. For you, on the other hand, it would be
different.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: const integral values across modules and ROM placement</title><link>https://community.arm.com/thread/136948?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2013 07:12:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0b985409-2c28-4c55-8f77-bd561282f2ca</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
The normal way for this would be:&lt;/p&gt;

&lt;pre&gt;
enum {
    C1_VAL = 25,
    C2_VAL = C1_VAL + 25,
};
&lt;/pre&gt;

&lt;p&gt;
And then _maybe_ create the c1 and c2 const variables but more
likely just make use of the enum values.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: const integral values across modules and ROM placement</title><link>https://community.arm.com/thread/127996?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2013 06:48:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:acb1825a-8b6a-43d4-96e1-f19faa96ffff</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
That is one of the problems with all compiler extensions in
existence. People get expectations that all other compilers must
support it. And that the compiler should have supported even more
language extensions not covered in the &amp;quot;must&amp;quot; list of the language
standard.&lt;/p&gt;

&lt;p&gt;
Huge amounts of people look at gcc and then blame all other
compilers for not &amp;quot;correctly&amp;quot; being able to compile their code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: const integral values across modules and ROM placement</title><link>https://community.arm.com/thread/119964?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2013 04:02:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f7162885-cdf2-4ec5-b57e-e139f05d5e99</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;It isn&amp;#39;t a limitation of the tools, but a too high expectation
by you.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
As far as expectations are concerned, this code shouldn&amp;#39;t even be
expected to compile at all --- not even with both definitions in the
same translation unit.&lt;/p&gt;

&lt;p&gt;
The C language definition explicitly requires that initializers
for static variables must be &amp;quot;constant expressions&amp;quot;. While it may
seem that values of other, const-qualified variables should be
allowed in constant expressions, they&amp;#39;re not. An implementation is
allowed to accept other forms (and this one apparently does), but it
is generally unwise to expect such things to just work, much less to
behave exactly in any particular way.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: const integral values across modules and ROM placement</title><link>https://community.arm.com/thread/106825?ContentTypeID=1</link><pubDate>Sat, 02 Feb 2013 13:04:27 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d9a1bb46-5dba-4a59-8caf-3f3338619aef</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Why should it be mentioned in the documentation?&lt;/p&gt;

&lt;p&gt;
It isn&amp;#39;t a limitation of the tools, but a too high expectation by
you.&lt;/p&gt;

&lt;p&gt;
But look at it further. Let&amp;#39;s say that the compiler did manage to
give the correct value of c2 with your cross-module optimization.
Then you change your file1.c and give c1 another value. By standard
compilation rules, file2.c should not be recompiled since it hasn&amp;#39;t
been changed, and neither have any #include file used.&lt;/p&gt;

&lt;p&gt;
So would you want cross-module optimizations to always recompile
100% of the program, just to solve this specific situation?&lt;/p&gt;

&lt;p&gt;
If a compiler documents cross-module optimizations, it will
document what it does. Not what it doesn&amp;#39;t do. If you buy a car, you
will get to know that it has ABS, anti-spin etc. You don&amp;#39;t get to
know that it does not have an espresso machine and that it doesn&amp;#39;t
have automatic detection of speed cameras.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: const integral values across modules and ROM placement</title><link>https://community.arm.com/thread/80949?ContentTypeID=1</link><pubDate>Sat, 02 Feb 2013 11:51:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4faffcae-3a0e-4df6-81b1-9cf166aded12</guid><dc:creator>Diaa Sami</dc:creator><description>&lt;p&gt;&lt;p&gt;
Well, I tried enabling cross-module optimizations but it didn&amp;#39;t
help.&lt;br /&gt;
It should be mentioned in the docs, thanks :)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: const integral values across modules and ROM placement</title><link>https://community.arm.com/thread/68056?ContentTypeID=1</link><pubDate>Sat, 02 Feb 2013 10:22:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ee743ded-92c5-4bde-8287-5e84e25c8c91</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;quot;Am I missing something ?&amp;quot;&lt;/p&gt;

&lt;p&gt;
The compiler can perform compile-time expression evaluations. But
only when all parts of the equation have known values at compile
time.&lt;/p&gt;

&lt;p&gt;
If c1 is in another module, then the expression c2 = c1 + 25 can
not be computed while compiling file2.c. But if the assign to c2
can&amp;#39;t be computed directly at compile time, but instead at run time,
then c2 can&amp;#39;t be stored in a read-only memory region.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>