<?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>topic Re: Segments in HCS12 controller. in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Segments-in-HCS12-controller/m-p/124816#M108</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Vignesh,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Strictly speaking, this post is in the wrong forum - the CW forum might be more appropriate for this type of query.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;There is a problem with your declaration of the third variable on two counts -&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT size="2"&gt;A missing semicolon, and&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;You are attempting to initialise a simple char variable with array data.&amp;nbsp; To prevent the compiler from complaining or a type mismatch, the following would be needed -&lt;BR /&gt;&lt;FONT face="Courier New"&gt;char testchar[] = "HELLO";&lt;BR /&gt;&lt;/FONT&gt;This will allocate six bytes on the stack (including a final null), and initialise to the given string data.&amp;nbsp; If the required string length is more than five characters, the following could be used -&lt;BR /&gt;&lt;FONT face="Courier New"&gt;char testchar[20] = "HELLO";&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT size="2"&gt;When a function is entered, stack space is allocated for all the local variables that are defined (but not static variables).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 25 Jul 2006 22:40:22 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2006-07-25T22:40:22Z</dc:date>
    <item>
      <title>Segments in HCS12 controller.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Segments-in-HCS12-controller/m-p/124815#M107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;HI,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Its a very basic question but it would be great if anybody can enlighten me, how it works..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In a function, we have declared couple of variables which are local to function. One of the local variable is initialized to some label. See below function for more clarity:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;void MyFunc()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; int test1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; int test2 = 2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; char testchar = "HELLO"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; /* These variables used here..*/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My question is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) How HCS12 knows test char is equal to "HELLO", when ever it control comes to this function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) As far my understanding is concerned, linker doesnt allocate memory for local variables. Then how controller knows, these variables declared inside the function?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pl. clarify my question.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Vignesh&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2006 21:11:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Segments-in-HCS12-controller/m-p/124815#M107</guid>
      <dc:creator>Vicky</dc:creator>
      <dc:date>2006-07-25T21:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Segments in HCS12 controller.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Segments-in-HCS12-controller/m-p/124816#M108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Vignesh,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Strictly speaking, this post is in the wrong forum - the CW forum might be more appropriate for this type of query.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;There is a problem with your declaration of the third variable on two counts -&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT size="2"&gt;A missing semicolon, and&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;You are attempting to initialise a simple char variable with array data.&amp;nbsp; To prevent the compiler from complaining or a type mismatch, the following would be needed -&lt;BR /&gt;&lt;FONT face="Courier New"&gt;char testchar[] = "HELLO";&lt;BR /&gt;&lt;/FONT&gt;This will allocate six bytes on the stack (including a final null), and initialise to the given string data.&amp;nbsp; If the required string length is more than five characters, the following could be used -&lt;BR /&gt;&lt;FONT face="Courier New"&gt;char testchar[20] = "HELLO";&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT size="2"&gt;When a function is entered, stack space is allocated for all the local variables that are defined (but not static variables).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2006 22:40:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Segments-in-HCS12-controller/m-p/124816#M108</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-07-25T22:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Segments in HCS12 controller.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Segments-in-HCS12-controller/m-p/124817#M109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;If you don't need to modify the string content, you can alternatively allocate a pointer on the stack, and the content of the string literal in the flash:&lt;BR /&gt;&lt;BR /&gt;const char* testchar = "HELLO";&lt;BR /&gt;&lt;BR /&gt;Here the linker does allocate the 6 bytes for "HELLO", and the compiler just uses 2 bytes for the pointer testchar on the stack (if it is necessary at all). So this is more efficient than the &lt;BR /&gt;&lt;BR /&gt;char testchar[] = "HELLO";&lt;BR /&gt;&lt;BR /&gt;syntax, but the string content is not modifiable or owned by the function, so it depends on what you need. I did add an explicit const to make sure the string does not get changed accidentally.&lt;BR /&gt;&lt;BR /&gt;For super long strings, by the way, don't initialize the string on the stack.&lt;BR /&gt;Write the value into it:&lt;BR /&gt;char testchar[100];&lt;BR /&gt;(void)strcpy(testchar, "HELLO");&lt;BR /&gt;This runs at lot faster as ANSI requires that otherwise all 100 bytes are initialized. It's a init all or nothing thing.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jul 2006 02:57:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Segments-in-HCS12-controller/m-p/124817#M109</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2006-07-27T02:57:46Z</dc:date>
    </item>
  </channel>
</rss>

