Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The relevant part of the C standard is section 6.3.2.1 "Lvalues, arrays, and function designators". Here's what it says about functions:</p> <blockquote> <p>A <em>function designator</em> is an expression that has function type. Except when it is the operand of the <code>sizeof</code> operator<sup>65</sup> or the unary <code>&amp;</code> operator, a function designator with type ‘‘function returning <em>type</em>’’ is converted to an expression that has type ‘‘pointer to function returning <em>type</em>’’.</p> <p>[footnote 65] Because this conversion does not occur, the operand of the <code>sizeof</code> operator remains a function designator and violates the constraint in 6.5.3.4 [ed: the constraint in 6.5.3.4 says that you may not apply <code>sizeof</code> to a function designator - it's a semantic error].</p> </blockquote> <p>An identifier that names a function is the simplest sort of "expression that has function type". So what this means is, if <code>foo</code> has been declared as a function, the identifier <code>foo</code> evaluates as a pointer to that function, <em>except</em> when it's the operand of <code>&amp;</code> (in which case the larger expression <code>&amp;foo</code> evaluates as a pointer to that function) or the operand of <code>sizeof</code> (in which case the larger expression, <code>sizeof(foo)</code>, provokes a compile error).</p> <p>tl,dr: When <code>foo</code> is a function, <code>foo</code> and <code>&amp;foo</code> are equivalent by definition. This is a special rule for functions. It's not entirely unlike the special rule for arrays, which also "decay" to pointers in many contexts (that rule is one paragraph up from the one I quoted).</p> <p>Aside: Yes, this means that the function-call operator <em>always</em> operates on a pointer-to-function. When <code>pfunc</code> is a pointer-to-function variable, <code>(*pfunc)()</code> is processed as if it read <code>(&amp;(*pfunc))()</code> ... or just <code>pfunc()</code>.</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