0

C11 standard says

6.3.2.1 Lvalues, arrays, and function designators

A function designator is an expression that has function type. Except when it is the operand of the sizeof operator, 65) or the unary & operator, a function designator with type ‘‘function returning type’’ is converted to an expression that has type ‘‘pointer to function returning type’’.

What is a "function returning type"? Is it the same as a function type?

Thanks.

  • 1
    From the discussion it looks like it just means a function pointer. Hense, the italicized type. – lakeweb Oct 19 '20 at 20:44
4

The wording of a "function returning type" just means a function defined as returning some type T, such as T f() { .... }.

The quoted clause just tells you that using the designator of the function, for example its name f, in an expression, would have the type "pointer to a function returning T". To be read with the following associative priorities: "pointer to " "a function returning T".

The wording avoids to say the name of the function, since the rule is anything that designates a function, including a dereferenced function pointer.

Example, with T being void:

void f(){ printf("Oops\n");}

int main(void) {
    void (*pf1)(), (*pf2)(); 
    void (*a[3])();  

    pf2 = &f;   // &f is the address of f, so a pointer to a function returning void
    pf1 = f;    // f is a function designator,  it's converted to a function pointer
    a[0]=f;     // same, but for the fun it's stored in an array of function pointers
    printf ("%lx %lx %lx %lx %lx\n", f, &f,  pf1, pf2, a[0]);  // all the same
    pf2();      // will call the function as well.  pf2 is already a function pointer
    
    (*pf1)();     // here we see that *pf1 is also a function designator
    pf2 = *pf1;   // *pf1 is converted to a function pointer, so it's pf1   
    printf ("%lx %lx\n", pf1, pf2);    // all the same 

    (***************pf1)(); // Sorry: I couldn't resist ;-)

    return 0;
} 
2

There are functions returning void, functions returning int, functions returning double, and so on. To speak about all those functions, you call them “functions returning type”.

  • 1
    Thanks, but I don't think the phrase means only the return type of a function – Tim Oct 19 '20 at 20:20
  • Exactly. It's not about the type of a function's return value, it's about the type of the function. – gnasher729 Oct 19 '20 at 22:04
  • 1
    @Tim - in the standard, the word "type" is typographically distinguished, to indicate that it's meant as a placeholder, e.g., it's written like this: "array of type" (meaning array of T) , and "function returning type" (meaning function with the return type T). It's not a phrase, it's a phrase template, if you will; perhaps another way to express it would be: "converted to an expression that has type: pointer to function returning <type>". – Filip Milovanović Oct 20 '20 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.