Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Casts are irrelevant, it's the (possibly implicit) prototype that matters.</p> <pre><code>void foo(short s) { // do something } int main(void) { signed char c = 'a'; foo(c); // c is promoted to short by explicit prototype bar(c); // c is promoted to int by implicit prototype } void bar(int i) { // do something } </code></pre> <p>When the book says "an argument of a function call is an expression" it means that the same type promotion rules apply. It might be easier to understand if you think of a function argument as an implicit assignment to the variable specified in the function prototype. e.g. in the call to <code>foo()</code> above there's an implicit <code>short s = c</code>.</p> <p>This is why casts don't matter. Consider the following code snippet:</p> <pre><code>signed char c = 'a'; int i = (short) c; </code></pre> <p>Here the value of c is promoted first to <code>short</code> (explicitly) then to <code>int</code> (implicitly). The value of <code>i</code> will always be an <code>int</code>.</p> <p>As for <code>char</code> and <code>short</code> becoming <code>int</code> and <code>float</code> becoming <code>double</code> that refers to the default types for implicit function prototypes. When the compiler sees a call to a function before it has seen either a prototype or the definition of the function it generates a prototype automatically. It defaults to <code>int</code> for integer values and <code>double</code> for floating-point values.</p> <p>If the eventual function declaration doesn't match to implicit prototype, you'll get warnings.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload