<?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: Pointer of Function in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201602#M16547</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Yes. Substracting one pointer from another when they aren't pointing at the same array is undefined behavior in C. Typecasting from a function pointer to any other pointer type is also undefined behavior, you can only cast to integer.&lt;BR /&gt;&lt;BR /&gt;The warning means that the code isn't legal C but that the compiler has made a non-standard extension to allow it. So the code will be non-portable.&lt;BR /&gt;&lt;BR /&gt;The quick &amp;amp; dirty way around it is to cast both pointers to integer, then substract, then cast the result back to a function pointer.&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Nov 2008 21:57:54 GMT</pubDate>
    <dc:creator>Lundin</dc:creator>
    <dc:date>2008-11-12T21:57:54Z</dc:date>
    <item>
      <title>Pointer of Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201598#M16543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I have some compilator errors due to pointer of function&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;void MyFunct(void)&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;.....&lt;/DIV&gt;&lt;DIV&gt;.....&lt;/DIV&gt;&lt;DIV&gt;.....&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;void main(void)&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;void (*MyPtrfunc) ();&lt;/DIV&gt;&lt;DIV&gt;MyPtrFunct = &amp;amp;MyFunct;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;MyPtrFunct&amp;nbsp;= MyPtrFunct - OffSetSW&amp;nbsp;&amp;nbsp;&amp;nbsp; //Compilator error desciption : Error C1829 : + - incompatible Type&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;MyPtrFunct();&lt;/DIV&gt;&lt;DIV&gt;}&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I already use this kind of declaration with another compilator, and i have no issue!!!&lt;/DIV&gt;&lt;DIV&gt;Do you have any about idea about my issue?&lt;/DIV&gt;&lt;DIV&gt;For you comprehension : Before run this command line, i rewrite Myfunction in spectific section in flash.&lt;/DIV&gt;&lt;DIV&gt;In fact, i try run a function place @ specific adress. This specific adress is Default adress (cofigured by emulator) - 0x1800.&lt;/DIV&gt;&lt;DIV&gt;Thanks&lt;/DIV&gt;&lt;DIV&gt;David&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Nov 2008 18:33:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201598#M16543</guid>
      <dc:creator>DavidoBG</dc:creator>
      <dc:date>2008-11-12T18:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: Pointer of Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201599#M16544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This is an ANSI C limitation you cannot use pointer arithmetic on function pointer.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Keep in mind that if you have a pointer to an int, ptr - 2 is in fact subtracting 4 (2 * sizeof(int)) from the pointer.&lt;/DIV&gt;&lt;DIV&gt;You cannot use sizeof on a function pointer, so you will not be able to use pointer arithmetic on such a pointer either&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;So you need to cast the function pointer to a pointer to char and do the arithmetic.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;CrasyCat&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Nov 2008 20:44:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201599#M16544</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2008-11-12T20:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Pointer of Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201600#M16545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;: This is an ANSI C limitation you cannot use pointer arithmetic on function pointer.&lt;BR /&gt;&lt;BR /&gt;I very much doubt this is true. Could you please cite the ISO standard?&lt;BR /&gt;&lt;BR /&gt;It is however indeed true that you can't use sizeof on function pointers.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Nov 2008 21:06:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201600#M16545</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2008-11-12T21:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Pointer of Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201601#M16546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;so my line programmation becomes&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;//OffsetSW = 0x1800 may be i must cast with unsigned int???&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;MyPtrFunct&amp;nbsp;= (char*)MyPtrFunct - OffSetSW&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Now i don't have any compilator error but a following warning appears :&lt;/DIV&gt;&lt;DIV&gt;Non stardart conversion used. Is it important??&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;David&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Nov 2008 21:36:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201601#M16546</guid>
      <dc:creator>DavidoBG</dc:creator>
      <dc:date>2008-11-12T21:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: Pointer of Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201602#M16547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Yes. Substracting one pointer from another when they aren't pointing at the same array is undefined behavior in C. Typecasting from a function pointer to any other pointer type is also undefined behavior, you can only cast to integer.&lt;BR /&gt;&lt;BR /&gt;The warning means that the code isn't legal C but that the compiler has made a non-standard extension to allow it. So the code will be non-portable.&lt;BR /&gt;&lt;BR /&gt;The quick &amp;amp; dirty way around it is to cast both pointers to integer, then substract, then cast the result back to a function pointer.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Nov 2008 21:57:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201602#M16547</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2008-11-12T21:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Pointer of Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201603#M16548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;OK thanks much&lt;/DIV&gt;&lt;DIV&gt;david&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2008 00:10:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201603#M16548</guid>
      <dc:creator>DavidoBG</dc:creator>
      <dc:date>2008-11-13T00:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Pointer of Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201604#M16549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;I would not call it a limitation, for me its just the way the language is defined.&lt;BR /&gt;&lt;BR /&gt;ANSI-C does not support pointer arithmetic for function pointers, more concretely ANSI-C defines pointer arithmetic for object type pointers only, here the definition for the addition:&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;PRE&gt;6.3.6  Additive operators&lt;/PRE&gt;....&lt;BR /&gt;&lt;PRE&gt;      [#2]  For  addition,  either  both   operands   shall   have
       arithmetic  type,  or  one  operand shall be a pointer to an
       object  type  and  the  other  shall  have   integer   type.
       (Incrementing is equivalent to adding 1.)
&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;And object types are distinct types form function types:&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;PRE&gt;6.1.2.5 Types...       Types  are  partitioned       into  object  types  (types that describe objects), function       types (types that describe functions), and incomplete  types       (types  that describe objects but lack information needed to       determine their sizes).&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;So in other words, ANSI-C does not support pointer arithmetic on function pointers.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;BR /&gt;PS: Snippets above copied from some C standard draft found on the web.&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by CompilerGuru on &lt;SPAN class="date_text"&gt;2008-11-12&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:24 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2008 05:23:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Pointer-of-Function/m-p/201604#M16549</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-11-13T05:23:59Z</dc:date>
    </item>
  </channel>
</rss>

