<?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 How do I call a function from a function pointer address in CW5.1(S9S12GA192)? in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/How-do-I-call-a-function-from-a-function-pointer-address-in-CW5/m-p/851226#M7565</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Environment:&lt;/P&gt;&lt;P&gt;IDE:Codewarior 5.1,MCU:&lt;SPAN style="font-size: 10.5pt;"&gt;MC9S12GA192&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;How do I call a function from a function pointer?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-family: Arial, 'Microsoft YaHei', '\ FAE软雅黑', '\ B8B体', 'Malgun Gothic', Meiryo, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #f7f8fa; display: inline !important; float: none;"&gt;1. If the function name of the called function is directly assigned to the pointer, it is ok to call the function with the pointer, and jump to the function:&lt;SPAN style="font-size: 10.5pt;"&gt;"HAL_E_IDLE_Task()"&lt;/SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;void (*function_ptr)(void);&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function_ptr = HAL_E_IDLE_Task;&amp;nbsp; &amp;nbsp;//&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;or &lt;SPAN lang="EN-US"&gt;"function_ptr = &amp;amp;HAL_E_IDLE_Task;"&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (*function_ptr)(); //&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;or &lt;SPAN lang="EN-US"&gt;"function_ptr();"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US"&gt;This will call the function successfully!&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="-webkit-text-stroke-width: 0px; color: #333333; white-space: normal; font-weight: normal; letter-spacing: normal; display: inline !important; font-size: 14px; line-height: 26px; font-style: normal; float: none; background-color: #f7f8fa; text-transform: none; word-spacing: 0px; font-variant: normal; text-indent: 0px; font-family: Arial, 'Microsoft YaHei', '\ FAE软雅黑', '\ B8B体', 'Malgun Gothic', Meiryo, sans-serif; orphans: auto; widows: auto; text-align: start;"&gt;2. But if the function is compiled after the link stored in flash address assigned to the pointer, and then call the function, the program will run away, can not enter the function "HAL_E_IDLE_Task()".&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&lt;SPAN style="-webkit-text-stroke-width: 0px; color: #333333; white-space: normal; font-weight: normal; letter-spacing: normal; display: inline !important; font-size: 14px; line-height: 26px; font-style: normal; float: none; background-color: #f7f8fa; text-transform: none; word-spacing: 0px; font-variant: normal; text-indent: 0px; font-family: Arial, 'Microsoft YaHei', '\ FAE软雅黑', '\ B8B体', 'Malgun Gothic', Meiryo, sans-serif; orphans: auto; widows: auto; text-align: start;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG&gt;void (*function_ptr)(void);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function_ptr = (void (*)())0x0000CF1F; //Function &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;"HAL_E_IDLE_T&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;ask()"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="-webkit-text-stroke-width: 0px; color: #666666; white-space: normal; letter-spacing: normal; display: inline !important; font-size: 14px; line-height: 20px; font-style: normal; float: none; background-color: #f7f8fa; text-transform: none; word-spacing: 0px; font-variant: normal; text-indent: 0px; font-family: Arial, 'Microsoft YaHei', '  FAE软雅黑', '  B8B体', 'Malgun Gothic', Meiryo, sans-serif; text-align: left;"&gt;compiled link addresses:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;"0x0000CF&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;1F"&amp;nbsp; &amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function_ptr(); //&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;or&lt;SPAN lang="EN-US"&gt;"(*function_ptr)();"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US"&gt;&amp;nbsp;This way can not call the function successfully!&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;&amp;nbsp;I need to call the function in the second way(Use Function Point address), how can I jump to the function "HAL_E_IDLE_Task()" correctly?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;PS:S32DS for SPC5744P(Power Architecture) use second way can &amp;nbsp;call the function successfully!It is&amp;nbsp; Complier reason?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Jan 2019 05:33:14 GMT</pubDate>
    <dc:creator>joophliu</dc:creator>
    <dc:date>2019-01-22T05:33:14Z</dc:date>
    <item>
      <title>How do I call a function from a function pointer address in CW5.1(S9S12GA192)?</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/How-do-I-call-a-function-from-a-function-pointer-address-in-CW5/m-p/851226#M7565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Environment:&lt;/P&gt;&lt;P&gt;IDE:Codewarior 5.1,MCU:&lt;SPAN style="font-size: 10.5pt;"&gt;MC9S12GA192&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;How do I call a function from a function pointer?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-family: Arial, 'Microsoft YaHei', '\ FAE软雅黑', '\ B8B体', 'Malgun Gothic', Meiryo, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #f7f8fa; display: inline !important; float: none;"&gt;1. If the function name of the called function is directly assigned to the pointer, it is ok to call the function with the pointer, and jump to the function:&lt;SPAN style="font-size: 10.5pt;"&gt;"HAL_E_IDLE_Task()"&lt;/SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;void (*function_ptr)(void);&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function_ptr = HAL_E_IDLE_Task;&amp;nbsp; &amp;nbsp;//&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;or &lt;SPAN lang="EN-US"&gt;"function_ptr = &amp;amp;HAL_E_IDLE_Task;"&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (*function_ptr)(); //&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;or &lt;SPAN lang="EN-US"&gt;"function_ptr();"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US"&gt;This will call the function successfully!&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="-webkit-text-stroke-width: 0px; color: #333333; white-space: normal; font-weight: normal; letter-spacing: normal; display: inline !important; font-size: 14px; line-height: 26px; font-style: normal; float: none; background-color: #f7f8fa; text-transform: none; word-spacing: 0px; font-variant: normal; text-indent: 0px; font-family: Arial, 'Microsoft YaHei', '\ FAE软雅黑', '\ B8B体', 'Malgun Gothic', Meiryo, sans-serif; orphans: auto; widows: auto; text-align: start;"&gt;2. But if the function is compiled after the link stored in flash address assigned to the pointer, and then call the function, the program will run away, can not enter the function "HAL_E_IDLE_Task()".&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&lt;SPAN style="-webkit-text-stroke-width: 0px; color: #333333; white-space: normal; font-weight: normal; letter-spacing: normal; display: inline !important; font-size: 14px; line-height: 26px; font-style: normal; float: none; background-color: #f7f8fa; text-transform: none; word-spacing: 0px; font-variant: normal; text-indent: 0px; font-family: Arial, 'Microsoft YaHei', '\ FAE软雅黑', '\ B8B体', 'Malgun Gothic', Meiryo, sans-serif; orphans: auto; widows: auto; text-align: start;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG&gt;void (*function_ptr)(void);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function_ptr = (void (*)())0x0000CF1F; //Function &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;"HAL_E_IDLE_T&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;ask()"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="-webkit-text-stroke-width: 0px; color: #666666; white-space: normal; letter-spacing: normal; display: inline !important; font-size: 14px; line-height: 20px; font-style: normal; float: none; background-color: #f7f8fa; text-transform: none; word-spacing: 0px; font-variant: normal; text-indent: 0px; font-family: Arial, 'Microsoft YaHei', '  FAE软雅黑', '  B8B体', 'Malgun Gothic', Meiryo, sans-serif; text-align: left;"&gt;compiled link addresses:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;"0x0000CF&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;1F"&amp;nbsp; &amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function_ptr(); //&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;or&lt;SPAN lang="EN-US"&gt;"(*function_ptr)();"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US"&gt;&amp;nbsp;This way can not call the function successfully!&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;&amp;nbsp;I need to call the function in the second way(Use Function Point address), how can I jump to the function "HAL_E_IDLE_Task()" correctly?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;PS:S32DS for SPC5744P(Power Architecture) use second way can &amp;nbsp;call the function successfully!It is&amp;nbsp; Complier reason?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;&lt;SPAN lang="EN-US"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jan 2019 05:33:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/How-do-I-call-a-function-from-a-function-pointer-address-in-CW5/m-p/851226#M7565</guid>
      <dc:creator>joophliu</dc:creator>
      <dc:date>2019-01-22T05:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do I call a function from a function pointer address in CW5.1(S9S12GA192)?</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/How-do-I-call-a-function-from-a-function-pointer-address-in-CW5/m-p/851227#M7566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many unknowns here. Memory model, etc.. Could you do project demonstrating the issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: medium;"&gt;void&lt;/SPAN&gt;&lt;SPAN style="font-size: medium;"&gt; (*function_ptr)(void)&lt;/SPAN&gt;&lt;/STRONG&gt; is not universal function pointer on S12. There are functions in nonpaged memory, which return with RST and have to be called using JSR/BSR. There are also functions in paged memory, which return with RTC and have to be called using CALL instruction. It is impossible on S12 to have same function pointer working with both function types. When compiler sees &lt;STRONG style="font-size: medium; "&gt;HAL_E_IDLE_Task() &lt;/STRONG&gt;&lt;SPAN style="font-size: medium;"&gt;declaration with all attributes like near, #pragma CODE_SEG __NEAR_SEG etc, you assing pointer and immediately call it (for testing purposes), compiler outsmarts your bug and uses JSR instruction. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: medium;"&gt;If all you need is to call nonpaged/paged functions via pointer, you need to use near/far keyword in your pointer declaration:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: medium;"&gt;void (* near function_ptr)(void);&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: medium;"&gt;Edward&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jan 2019 08:40:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/How-do-I-call-a-function-from-a-function-pointer-address-in-CW5/m-p/851227#M7566</guid>
      <dc:creator>kef2</dc:creator>
      <dc:date>2019-01-25T08:40:57Z</dc:date>
    </item>
  </channel>
</rss>

