<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/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/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>NCS Does Not Respect C Rule Against Function Overloads Under Certain Conditions</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/114050/ncs-does-not-respect-c-rule-against-function-overloads-under-certain-conditions</link><description>During a review of production firmware I noticed an oddity that should cause a compiler error but it somehow does not. 
 In C, a function may not be overloaded. There are exceptions to this (with _Generic), but we are not engaging with this functionality</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 20 Aug 2024 16:31:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/114050/ncs-does-not-respect-c-rule-against-function-overloads-under-certain-conditions" /><item><title>RE: NCS Does Not Respect C Rule Against Function Overloads Under Certain Conditions</title><link>https://devzone.nordicsemi.com/thread/499107?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2024 16:31:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c62f1bbc-e132-44ce-9e1e-a56647a324b5</guid><dc:creator>ActiBaker</dc:creator><description>&lt;p&gt;Ahh, I was unaware this was a &amp;quot;feature&amp;quot; of C in the old days. I looked around the internet with better keywords (incomplete function prototype) and found that the compiler setting&amp;nbsp;&lt;code&gt;-Wstrict-prototypes&lt;/code&gt; will mark instances of this.&lt;/p&gt;
&lt;p&gt;I now understand the value of placing void in the parameter list, like &lt;code&gt;void test(void)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Thanks for your help, Priyanka.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS Does Not Respect C Rule Against Function Overloads Under Certain Conditions</title><link>https://devzone.nordicsemi.com/thread/499058?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2024 12:50:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4227661-f48b-473b-892c-4aee955bc86a</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;There are usually 2 compiler settings. &amp;nbsp;One for treat warnings as error. The other is disable all warning. &amp;nbsp;Normally this should show a warning. If you don&amp;#39;t see it, the disable all warnings may be active. Unfortunately, I don&amp;#39;t know where those settings are in NCS. Look for the compiler settings. &amp;nbsp;You might find tons of warning once you enable it. ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS Does Not Respect C Rule Against Function Overloads Under Certain Conditions</title><link>https://devzone.nordicsemi.com/thread/499055?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2024 12:39:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2114c9fe-7f59-4ebe-b338-9361421c8f33</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This likely occurs because of how lenient or strict different compilers are with the checking. In your case, even though function overloading is not allowed, you actually have two versions of the test function.&lt;/p&gt;
&lt;p&gt;So in your sample, you first have a function declaration as:&lt;/p&gt;
[quote user=""]void test();[/quote]
&lt;p&gt;Now, C is less strict about function declarations compared to C++. Hence when you have this declaration it likely understands it as a function which can take any arguments and return a void. So later when you have the definition as follows:&lt;/p&gt;
[quote user=""]&lt;code&gt;void test(void * arg)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;{&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; arbitrary_code();&lt;/code&gt;&lt;br /&gt;&lt;code&gt;}&lt;/code&gt;[/quote]
&lt;p&gt;It does not actually violate what you have declared before. What you have done here is incomplete function prototyping. Certain compilers are lenient with this and others like the IAR are a bit more strict with this. The better solution is to avoid incomplete function prototyping and declare it properly always.&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>