<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Assume that you are using C and C has a facility to bind together object modules from different files.<div class=""><br class=""></div><div class="">You define a function in one file, it has a bunch of parameters and doesn’t return anything.</div><div class=""><br class=""></div><div class="">In another file you use that function but don’t have a prototype that tells the compiler anything about the function.</div><div class=""><br class=""></div><div class="">Now assume that the compiler was written in 1972, and doesn’t benefit from things like mind reading.</div><div class=""><br class=""></div><div class="">C assumes, by default, that <b style="font-size: 14px;" class="">a function has one integer parameter and returns an integer, unless otherwise told</b>. What other choices has it got? Nothing really. </div><div class=""><br class=""></div><div class="">So in later versions of C, they introduced a thing called a prototype that gives the compiler a hint about the parameters and return values of a function.</div><div class=""><br class=""></div><div class="">All that you needed was to take your function header, put a semicolon on the end and paste it before the call to the function and the compiler would have done what you wanted instead of what you said.</div><div class=""><br class=""></div><div class="">Better yet, take that prototype and put it into a header file and whenever you want to call the function, put in an include statement, the compiler get’s the information about the parameters and return values, and overrides the<font face="Times" class=""> <b class="">int func( int)</b></font> default nature.</div><div class=""><br class=""></div><div class="">A<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 2019-June-26, at 12:41 AM, Jython <<a href="mailto:googcheng@gmail.com" class="">googcheng@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class="">I have a function named 
<b class="">oled_write_temp</b>

 in a.c, if i dont declare it in a.h , then i will get the wrong 
supply value in the function within main call, why?</div><div class=""><br class=""></div><div class="">if i 
declare it in a.h, then all is right<br class=""></div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="">void oled_write_temp(float set_temp, const float supply, float return_temp)<br class="">{<br class=""><br class="">    int base_x = 12, base_y = 60;<br class=""><br class="">    char buffer[20] = {0};<br class=""><br class="">    <b class="">printf("supply_temp %f at %s\n", supply, __FUNCTION__);</b><br class="">    <br class="">    snprintf(buffer, 20, "SUPPLY:%.2f", supply);<br class="">    printf("supply_temp string %s\n", buffer);<br class=""><br class="">    oled_clear_area(base_x, base_y + 16, 122, base_y + 32);<br class="">    OLED_ShowString(base_x, base_y + 16, buffer, 16, 1);<br class=""><br class="">    memset(buffer, 0, sizeof(buffer));<br class="">    snprintf(buffer, 20, "RETURN:%.2f", return_temp);<br class="">    OLED_ShowString(base_x, base_y + 36, buffer, 16, 1);<br class=""><br class="">    memset(buffer, 0, sizeof(buffer));<br class="">    snprintf(buffer, 20, "SET   :%.2f", set_temp);<br class="">    OLED_ShowString(base_x, base_y + 56, buffer, 16, 1);<br class=""><br class="">}<br class=""></div></blockquote><div class=""><br class=""></div><div class="">ps: watch line 
<b class="">printf("supply_temp %f at %s\n", supply, __FUNCTION__);</b>

 </div></div></div></div>
_______________________________________________<br class="">users mailing list<br class=""><a href="mailto:users@rtems.org" class="">users@rtems.org</a><br class="">http://lists.rtems.org/mailman/listinfo/users</div></blockquote></div><br class="">
<br class=""></div></body></html>