<div dir="ltr"><font face="arial, helvetica, sans-serif">Hi, </font><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><span style="color:rgb(36,39,41)">I am a beginner to C and I previously asked this question on SO (and it was marked as duplicate :-) ) </span><span style="color:rgb(36,39,41)">I still do not understand the problem to the end. </span><span style="color:rgb(36,39,41)">I understand the need of function prototypes and the default argument promotion machinery. But </span></font><span style="font-family:arial,helvetica,sans-serif;color:rgb(36,39,41)">I am still confused with the obtained warning and final result for this example:</span></div><div><span style="font-family:arial,helvetica,sans-serif;color:rgb(36,39,41)"><br></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both;color:rgb(36,39,41)"><font face="monospace, monospace">#include <stdio.h></font></p></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both;color:rgb(36,39,41)"><span style="font-family:monospace,monospace">void impl();</span></p></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both;color:rgb(36,39,41)"><font face="monospace, monospace">int main(void)</font><span style="font-family:monospace,monospace">{</span></p></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both;color:rgb(36,39,41)"><font face="monospace, monospace">impl(3.0);</font></p></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both;color:rgb(36,39,41)"><font face="monospace, monospace">return 0; </font></p></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><span style="font-family:monospace,monospace;color:rgb(36,39,41)">}<br></span><br></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both;color:rgb(36,39,41)"><font face="monospace, monospace">void impl(val)</font><span style="font-family:monospace,monospace">{</span></p></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both;color:rgb(36,39,41)"><font face="monospace, monospace">printf("%.2f", val);</font></p></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both;color:rgb(36,39,41)"><font face="monospace, monospace">}</font></p></div></blockquote><font face="arial, helvetica, sans-serif"><span style="color:rgb(36,39,41)">I get the following warning: </span><span style="margin:0px;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;color:rgb(36,39,41)"><code style="margin:0px;padding:1px 5px;border:0px;font-style:inherit;font-variant:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;white-space:pre-wrap;background-color:rgb(255,255,255)"><b>format specifies type 'double' but the argument has type 'int' [-Wformat].</b></code></span><span style="color:rgb(36,39,41)">I can not understand why it is supposed by a compiler that</span><span style="color:rgb(36,39,41)"> </span><code style="color:rgb(36,39,41);font-style:inherit;font-variant:inherit;margin:0px;padding:1px 5px;border:0px;font-stretch:inherit;line-height:inherit;vertical-align:baseline;white-space:pre-wrap;background-color:rgb(255,255,255)"><b>val</b></code><span style="color:rgb(36,39,41)"> </span><span style="color:rgb(36,39,41)">should be treated as</span><span style="color:rgb(36,39,41)"> </span><code style="color:rgb(36,39,41);font-style:inherit;font-variant:inherit;margin:0px;padding:1px 5px;border:0px;font-stretch:inherit;line-height:inherit;vertical-align:baseline;white-space:pre-wrap;background-color:rgb(255,255,255)"><b>int</b></code><span style="color:rgb(36,39,41)"> </span><span style="color:rgb(36,39,41)">and not to skip the number and types of arguments and then perform default argument promotion at run time. Also I read that if you don't provide argument types in ANSI C:</span></font><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-family:arial,helvetica,sans-serif;font-style:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit;color:rgb(36,39,41)">An ANSI C compiler will assume that you have decided to forego function prototyping, and it will not check arguments.</span></blockquote><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both;color:rgb(36,39,41)"><font face="arial, helvetica, sans-serif">The result which is printed to the console is <strong style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline"><code style="margin:0px;padding:1px 5px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;white-space:pre-wrap;background-color:rgb(255,255,255)">0.00</code></strong>, but as I understood the caller should place double on the stack and <code style="margin:0px;padding:1px 5px;border:0px;font-style:inherit;font-variant:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;white-space:pre-wrap;background-color:rgb(255,255,255)"><b>%f</b></code> also means double in <code style="margin:0px;padding:1px 5px;border:0px;font-style:inherit;font-variant:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;white-space:pre-wrap;background-color:rgb(255,255,255)"><b>printf</b></code> so it reads double off the stack, and the result should not be affected. </font></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both"><font face="arial, helvetica, sans-serif" style="color:rgb(36,39,41)">So I'm still confused what is happening here. Also I can't find where it is stated that the argument without a type should be treated by a compiler as type <code style="margin:0px;padding:1px 5px;border:0px;font-style:inherit;font-variant:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;white-space:pre-wrap;background-color:rgb(255,255,255)"><b>int</b></code>. </font><font color="#242729" face="arial, helvetica, sans-serif">I understand that the question is stupid in nature, for this I apologize in advance, but it somehow sat down in my head and I nowhere can I find why it happens. Thank you!</font></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both"><font color="#242729" face="arial, helvetica, sans-serif">p.s.: </font><font face="arial, helvetica, sans-serif"><span style="color:rgb(36,39,41)">Compiled with </span><code style="margin:0px;padding:1px 5px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;white-space:pre-wrap;color:rgb(36,39,41);background-color:rgb(255,255,255)"><b>clang 6.0</b></code><span style="color:rgb(36,39,41)"> and </span><code style="margin:0px;padding:1px 5px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;white-space:pre-wrap"><font color="#000000" style="background-color:rgb(255,255,255)"><b>--std=c89</b></font></code><span style="color:rgb(36,39,41)"> flag under Windows 10. Apologies if this question is off-topic for this list, but i can't find any other.</span></font></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both">With kind regards,</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;clear:both">-gdg</p></div></div>