<?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>ColdFire/68K Microcontrollers and ProcessorsのトピックRe: simple atoi() function on CF V1</title>
    <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/simple-atoi-function-on-CF-V1/m-p/157767#M4748</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Daniel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Indeed, this error was my own poor understanding of the C language pointer syntax in general.&amp;nbsp; ;o)&lt;/P&gt;&lt;P&gt;10 years without coding will do that to you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By using&amp;nbsp; &lt;FONT face="courier new,courier"&gt;atoi(&amp;amp;tempbuf[0])&lt;/FONT&gt;&amp;nbsp; or &lt;FONT face="courier new,courier"&gt;atoi(tempbuf+0)&lt;/FONT&gt; the compile error went away.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error was:&amp;nbsp; &lt;FONT face="terminal,monaco"&gt;illegal implicit converstion from 'char' to 'const char *'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the bracket [0] because I need an index in the string, i.e&amp;nbsp;&amp;nbsp; tempbuf[k] where k points at different locations.&lt;/P&gt;&lt;P&gt;the sample code is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch (parse_state)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case JobParseState_head:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((tempbuf[k]==0)||(tempbuf[k]=='*'))&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; job.Job_id = atoi(tempbuf[k]);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do { k++;} while (tempbuf[k]!=' ');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k++;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ..... &amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I agree with you that&amp;nbsp; the address space is flat but&amp;nbsp; the modifier &lt;FONT face="courier new,courier"&gt;const&lt;/FONT&gt;&amp;nbsp; tells the compiler that the variable is not&amp;nbsp; changed during execution and it gets placed in the same segment as code (.rodata and .text respectively). The linker command file then places them into the flash portion of that linear address space.&amp;nbsp; (&lt;FONT face="courier new,courier"&gt;0x0&lt;/FONT&gt; on the MCF51AC256)&lt;/P&gt;&lt;P&gt;I guess what threw me off is the difference between &lt;FONT face="courier new,courier"&gt;atoi(tempbuf+k)&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;atoi(tempbuf[k])&lt;/FONT&gt; when accessing a char array. It has nothing to do with &lt;FONT face="courier new,courier"&gt;const&lt;/FONT&gt; from my embedded point of view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At any rate... thank you !!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 27 Apr 2012 00:39:01 GMT</pubDate>
    <dc:creator>exfae</dc:creator>
    <dc:date>2012-04-27T00:39:01Z</dc:date>
    <item>
      <title>simple atoi() function on CF V1</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/simple-atoi-function-on-CF-V1/m-p/157765#M4746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi group,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have just ran into a snag that I dearly hope has an easy fix.&lt;/P&gt;&lt;P&gt;Have been using the MCF51AC256 on a project for a while now and all is great... so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an ASCII string coming in from the serial port that is &lt;STRONG&gt;&lt;EM&gt;obviously&lt;/EM&gt;&lt;/STRONG&gt; stored into a &lt;SPAN style="font-family: 'courier new,courier';"&gt;char&lt;/SPAN&gt; array in ram , say &lt;SPAN style="font-family: 'courier new,courier';"&gt;char tempbuf[100]&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;The application needs to convert this string of 0 to 9 into an integer. Simple right?&lt;/P&gt;&lt;P&gt;When I use the standard library atoi() function, I get compile errors because it actually wants a &lt;STRONG&gt;constant&lt;/STRONG&gt; string from code space as if any and all application of &lt;SPAN style="font-family: 'courier new,courier';"&gt;atoi()&lt;/SPAN&gt; would be in the &lt;SPAN style="font-family: 'courier new,courier';"&gt;atoi("12345")&lt;/SPAN&gt; format instead of &lt;SPAN style="font-family: 'courier new,courier';"&gt;atoi(tempbuf[0])&lt;/SPAN&gt; .&lt;/P&gt;&lt;P&gt;Digging into it, the &lt;SPAN style="font-family: 'courier new,courier';"&gt;atoi&lt;/SPAN&gt; is actually a define that points to strtol() function and it expects a &lt;SPAN style="font-family: 'courier new,courier';"&gt;const string ptr*&lt;/SPAN&gt; (rom based from my understanding) as opposed to my RAM based string ptr*.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a quick fix to tell the function to get it's &lt;SPAN style="font-family: 'courier new,courier';"&gt;const&lt;/SPAN&gt; from ram instead?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope my somewhat limited knowledge of the standard MSL is at fault here.&lt;/P&gt;&lt;P&gt;Thank you in advance for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Apr 2012 10:25:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/simple-atoi-function-on-CF-V1/m-p/157765#M4746</guid>
      <dc:creator>exfae</dc:creator>
      <dc:date>2012-04-26T10:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: simple atoi() function on CF V1</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/simple-atoi-function-on-CF-V1/m-p/157766#M4747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you provide, copy paste, the exact error you get?&lt;/P&gt;&lt;P&gt;CF does not differentiate rom pointers from data pointers. Everything is in a flat 32 bit address space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure what a "const string ptr*" is, did you mean "const char ptr*". A function expecting a "const char*" should be callable with a char* pointer (or a char array) without any troubles.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also the sample should not be "atoi(tempbuf[0])" but&amp;nbsp;&lt;SPAN&gt;atoi(tempbuf) or&amp;nbsp;&lt;SPAN&gt;atoi(&amp;amp;tempbuf[0]), is that the actual issue?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Make sure to include &amp;lt;stdlib.h&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW: atoi does not allow to detect parsing errors, so using&amp;nbsp;strtol might be beneficial.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Apr 2012 11:06:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/simple-atoi-function-on-CF-V1/m-p/157766#M4747</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2012-04-26T11:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: simple atoi() function on CF V1</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/simple-atoi-function-on-CF-V1/m-p/157767#M4748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Daniel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Indeed, this error was my own poor understanding of the C language pointer syntax in general.&amp;nbsp; ;o)&lt;/P&gt;&lt;P&gt;10 years without coding will do that to you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By using&amp;nbsp; &lt;FONT face="courier new,courier"&gt;atoi(&amp;amp;tempbuf[0])&lt;/FONT&gt;&amp;nbsp; or &lt;FONT face="courier new,courier"&gt;atoi(tempbuf+0)&lt;/FONT&gt; the compile error went away.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error was:&amp;nbsp; &lt;FONT face="terminal,monaco"&gt;illegal implicit converstion from 'char' to 'const char *'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the bracket [0] because I need an index in the string, i.e&amp;nbsp;&amp;nbsp; tempbuf[k] where k points at different locations.&lt;/P&gt;&lt;P&gt;the sample code is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch (parse_state)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case JobParseState_head:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((tempbuf[k]==0)||(tempbuf[k]=='*'))&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; job.Job_id = atoi(tempbuf[k]);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do { k++;} while (tempbuf[k]!=' ');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k++;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ..... &amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I agree with you that&amp;nbsp; the address space is flat but&amp;nbsp; the modifier &lt;FONT face="courier new,courier"&gt;const&lt;/FONT&gt;&amp;nbsp; tells the compiler that the variable is not&amp;nbsp; changed during execution and it gets placed in the same segment as code (.rodata and .text respectively). The linker command file then places them into the flash portion of that linear address space.&amp;nbsp; (&lt;FONT face="courier new,courier"&gt;0x0&lt;/FONT&gt; on the MCF51AC256)&lt;/P&gt;&lt;P&gt;I guess what threw me off is the difference between &lt;FONT face="courier new,courier"&gt;atoi(tempbuf+k)&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;atoi(tempbuf[k])&lt;/FONT&gt; when accessing a char array. It has nothing to do with &lt;FONT face="courier new,courier"&gt;const&lt;/FONT&gt; from my embedded point of view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At any rate... thank you !!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Apr 2012 00:39:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/simple-atoi-function-on-CF-V1/m-p/157767#M4748</guid>
      <dc:creator>exfae</dc:creator>
      <dc:date>2012-04-27T00:39:01Z</dc:date>
    </item>
  </channel>
</rss>

