<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Classic/Legacy CodeWarriorのトピックRe: const variables to ROM</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/const-variables-to-ROM/m-p/135322#M820</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;The declaration CONST should be treated to mean "READ ONLY". It has nothing to do with RAM or ROM, as you found.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 May 2006 03:36:06 GMT</pubDate>
    <dc:creator>UK_CF_FAE</dc:creator>
    <dc:date>2006-05-11T03:36:06Z</dc:date>
    <item>
      <title>const variables to ROM</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/const-variables-to-ROM/m-p/135319#M817</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;I'm new to this forum, but I have been reading quite a few threads in the hope to find some clues as to how I should make const declared variables end up in ROM instead of RAM. I haven't found the answer yet, so I was hoping to get some help here...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm using CW5.5 and the target is the GC16 (1kB RAM) microcontroller (I'm new to this too...).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;What I have is something like this:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;in the .prm file:&lt;/DIV&gt;&lt;BLOCKQUOTE class="jive-quote" dir="ltr"&gt;&lt;DIV&gt;SEGMENTS&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;RAM = READ_WRITE 0x0C00 TO 0x0FFF; //9S12GC16&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* unbanked FLASH ROM */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ROM_C000 = READ_ONLY&amp;nbsp; 0xC000 TO 0xFEFF; //9S12GC16&lt;BR /&gt;END&lt;/DIV&gt;&lt;DIV&gt;PLACEMENT&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;_PRESTART, STARTUP,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ROM_VAR, STRINGS,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VIRTUAL_TABLE_SEGMENT,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;DEFAULT_ROM, NON_BANKED&amp;nbsp; ,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;OTHER_ROM&amp;nbsp; , COPY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTO&amp;nbsp; ROM_C000;&amp;nbsp; //9S12GC16&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;DEFAULT_RAM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTO&amp;nbsp; RAM;&lt;BR /&gt;END&lt;/DIV&gt;&lt;DIV&gt;STACKSIZE 0x100&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;in my c-file.&lt;/DIV&gt;&lt;BLOCKQUOTE class="jive-quote" dir="ltr"&gt;&lt;DIV&gt;static const unsigned char a[ ] = {1, 5};&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char b[ ] = {2, 6};&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char c[ ] = {3, 7};&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char d[ ] = {4, 8};&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char* p_misc_0[ ] = {a, b};&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char* p_misc_1[ ] = {c, d};&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char** p_misc[ ] = {p_misc_0, p_misc_1};&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In the .map file I then find the following:&lt;/DIV&gt;&lt;UL&gt;&lt;LI&gt;a,b,c, and d all end up in .rodata (ROM as expected)&lt;/LI&gt;&lt;LI&gt;p_misc_0, p_misc_1, and p_misc all end up in .data (RAM!)&lt;/LI&gt;&lt;LI&gt;All "non const" declared variables end up in .bss&amp;nbsp;(RAM)&lt;/LI&gt;&lt;/UL&gt;&lt;DIV&gt;I believe that this is in the&amp;nbsp;ELF object file&amp;nbsp;format, and therefore #pragma&amp;nbsp;INTO_ROM&amp;nbsp;cannot be used.&amp;nbsp;(Using this directive will fool the .mcp window to not count the variables as data, but the linker is not buying it!) I've been browsing the CW help for hours, but it just gets me confused, what with all the pragma directives and compiler options available...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'd like to think that there's an easy way to put the const vars in ROM. Any help is much appreciated.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;Anders.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 May 2006 21:43:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/const-variables-to-ROM/m-p/135319#M817</guid>
      <dc:creator>Anders</dc:creator>
      <dc:date>2006-05-09T21:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: const variables to ROM</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/const-variables-to-ROM/m-p/135320#M818</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi,&lt;BR /&gt;Years ago I had a similiar problem with a 'Cosmic' C compiler.&lt;BR /&gt;It turnes out that a declaration:&lt;BR /&gt;const char *pcA;&lt;BR /&gt;declares a pointer to constant char, what you want is a contant pointer to character which, I think looks like this:&lt;BR /&gt;char (const *) pcA;&lt;BR /&gt;But, as I mentioned, this was more than 10 years ago... so I can't say for sure if the syntax is right.&lt;BR /&gt;The idea is that there is a difference between a pointer to constant and a constant pointer. Please try one of those declarations and let me know which ones work, can't find my old code at the moment...&lt;BR /&gt;char (const *) pcA;&lt;BR /&gt;const char const *pcA;&lt;BR /&gt;char const *pcA;&lt;BR /&gt;char (const*) pcA;&lt;BR /&gt;char *(const) pcA;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 May 2006 00:35:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/const-variables-to-ROM/m-p/135320#M818</guid>
      <dc:creator>KrisRutecki</dc:creator>
      <dc:date>2006-05-10T00:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: const variables to ROM</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/const-variables-to-ROM/m-p/135321#M819</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Thanks!&lt;/DIV&gt;&lt;DIV&gt;Your reply solved it. I was actually thinking along these lines earlier today, but eventually gave up. I felt a bit stupid trying to insert a "const" at random places in the declaration. Your post gave me new hope, so I Googled a bit and came up with the following: (Note. The below syntax is not covered by any of your suggestions, which I hope shows that you do not nesessarily have to be stupid not to get it right the first time;-)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BLOCKQUOTE dir="ltr"&gt;&lt;DIV&gt;&lt;DIV&gt;static const unsigned char a[ ] = {1, 5};&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char b[ ] = {2, 6};&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char c[ ] = {3, 7};&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char d[ ] = {4, 8};&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;static const unsigned char* const p_misc_0[ ] = {a, b};&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char* const p_misc_1[ ] = {c, d};&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;static const unsigned char* const * const p_misc[ ] = {p_misc_0, p_misc_1};&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;I think I like that last declaration the best....&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Again, thanks.&lt;BR /&gt;Anders.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 May 2006 02:30:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/const-variables-to-ROM/m-p/135321#M819</guid>
      <dc:creator>Anders</dc:creator>
      <dc:date>2006-05-10T02:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: const variables to ROM</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/const-variables-to-ROM/m-p/135322#M820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;The declaration CONST should be treated to mean "READ ONLY". It has nothing to do with RAM or ROM, as you found.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 May 2006 03:36:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/const-variables-to-ROM/m-p/135322#M820</guid>
      <dc:creator>UK_CF_FAE</dc:creator>
      <dc:date>2006-05-11T03:36:06Z</dc:date>
    </item>
  </channel>
</rss>

