<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Problem with pointer to function</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/23535/problem-with-pointer-to-function</link><description> 
Hello, 

 
data char var;
void (code * data fptr)(void);

void fun(void)
{
 var = 10;
}

void main(void)
{
 fptr = fun;
 (*fptr)(); // OK!
 (*(fptr = fun))(); // This line generates bad code!
 (*(fptr = &amp;amp;fun))(); // OK!
 while (1);
}
 

 
 
Genereted</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Problem with pointer to function</title><link>https://community.arm.com/thread/114605?ContentTypeID=1</link><pubDate>Thu, 15 Jan 2009 07:42:19 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f413c836-7169-4697-baf2-97ab6f7af23e</guid><dc:creator>Stewart J Cort</dc:creator><description>&lt;p&gt;&lt;p&gt;
This looks like a generic vs. memory specific pointer issue. I
believe the tools expect a function pointer to contain a 3-byte
generic value.&lt;/p&gt;

&lt;p&gt;
Try defining the function pointer without the &amp;quot;code&amp;quot; option. By
specifying &amp;quot;code&amp;quot; as the pointer type, it only passes two bytes on to
the library, for de-refrencing.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with pointer to function</title><link>https://community.arm.com/thread/114593?ContentTypeID=1</link><pubDate>Thu, 15 Jan 2009 07:01:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bf1e7f44-8d97-4858-af36-48401672636c</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;On the other hand, I&amp;#39;d question why Henri would put &amp;#39;code&amp;#39;
there to begin with?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
The &lt;b&gt;code&lt;/b&gt; modifier is redundant as the manual says:&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_le_code.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_le_code.htm&lt;/a&gt;&lt;br /&gt;

But the &lt;b&gt;code&lt;/b&gt; modifier is not forbidden here. It shouldn&amp;#39;t make
any difference. This still looks like compiler bug.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with pointer to function</title><link>https://community.arm.com/thread/101538?ContentTypeID=1</link><pubDate>Thu, 15 Jan 2009 05:59:14 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:46576ef3-a783-4041-8501-6a1ca8553269</guid><dc:creator>ashley madison</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;But it doesn&amp;#39;t change the fact that what Henri describes looks
very much like a compiler bug.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
On the other hand, I&amp;#39;d question why Henri would put &amp;#39;code&amp;#39; there
to begin with?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with pointer to function</title><link>https://community.arm.com/thread/89498?ContentTypeID=1</link><pubDate>Thu, 15 Jan 2009 05:13:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:25abcfec-8074-4f3c-b196-960e46b761ed</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;because of the &amp;#39;restrictions&amp;#39; resulting from the &amp;#39;51
architecture function pointers are, at best, kludged into c for the
&amp;#39;51.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Perhaps. But it doesn&amp;#39;t change the fact that what Henri describes
looks very much like a compiler bug.&lt;/p&gt;

&lt;p&gt;
- mike&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with pointer to function</title><link>https://community.arm.com/thread/89497?ContentTypeID=1</link><pubDate>Thu, 15 Jan 2009 05:10:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c715dd5a-2335-4d63-adf7-c7cfb8bc283b</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
....&lt;br /&gt;
that with any other architecture (that I have worked with) I have
used function pointers when practical with no hesitation.&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with pointer to function</title><link>https://community.arm.com/thread/53289?ContentTypeID=1</link><pubDate>Thu, 15 Jan 2009 04:49:57 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:29090ab0-227b-4a2d-865b-d9f32a60de75</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
because of the &amp;#39;restrictions&amp;#39; resulting from the &amp;#39;51 architecture
function pointers are, at best, kludged into c for the &amp;#39;51.&lt;/p&gt;

&lt;p&gt;
the simple solution:&lt;br /&gt;
do not use function pointers.&lt;/p&gt;

&lt;p&gt;
Yes, it can be done, but require a lot of care, intervention and
also a lot of processing time.&lt;/p&gt;

&lt;p&gt;
what is wrong with&lt;br /&gt;
if (x)&lt;br /&gt;
{ y():&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
or&lt;br /&gt;
switch (x)&lt;br /&gt;
case y:&lt;br /&gt;
z();&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>