Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is function designator and actual call?

According to C99 Standard:

The order of evaluation of the function designator, the actual arguments, and subexpressions within the actual arguments is unspecified, but there is a sequence point before the actual call.

Could anyone explain clearly what is function designator and actual call; and what is difference between them ?

like image 775
Ulaş Sezgin Avatar asked Jun 02 '20 11:06

Ulaş Sezgin


3 Answers

A function designator is an expression with function type. That is, when you type func(a,b); to call a function, func is the function designator.

(Such a function designator when present in an expression normally "decays" into a pointer to function, much like arrays decay into a pointer to the first element.)

The meaning of "sequence point before the actual call" is that all operands must be fully evaluated (executed) before the function is called. If you have func(a(), b()), it is unspecified if a() or b() is executed first, but you know that both of them are definitely executed before func is called.

So if a() for example modified a global variable that is also used by func, that would be fine because the access to that variable would be sequenced in a well-defined order.


EDIT - sources

There's C17 6.5.2.2 requiring a function pointer whenever a function is called:

Constraints
The expression that denotes the called function shall have type pointer to function returning void or returning a complete object type other than an array type.

This is made possible by mandatory "function decay", C17 6.3.2.1/4:

A function designator is an expression that has function type. Except when it is the operand of the sizeof operator, 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".

like image 192
Lundin Avatar answered Oct 23 '22 15:10

Lundin


I would assume that the function designator is what tells the program which function to call. It might be either a function name or an expression resulting in a function pointer.

Edit:

Here is a function pointer example:

// Two random functions
int foo(int i);
int bar(int i);

// define a function pointer type
typedef int (* func)(int)

// Array of functions

func a[] = {foo, bar}


// calling bar(123)
// (a[1]) is an expression that evaluates to a pointer to `bar`

(a[1])(123);
like image 39
HAL9000 Avatar answered Oct 23 '22 14:10

HAL9000


"What is a function designator?"


A function designator is an expression that has function type. Except when it is the operand of the sizeof operator, 66) 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".

66) Because this conversion does not occur, the operand of the sizeof operator remains a function designator and violates the constraints in 6.5.3.4.

Source: C18, §6.3.2.1/4 - "Lvalues, arrays, and function designators"


A function designator is an expression which identifies a certain function and that designates a function when evaluated.

int tip (int);

tip (the name of the function) is for example a function designator.

Or for example in:

#include <stdio.h>

int tip (int a) {
    return a;
}

int main (void) {

    int (**foo)(int);

    int (*bar[5])(int);

    bar[0] = &tip;

    foo = &bar;

    printf("%d", (**foo)(4));
}

The pointer to pointer to function returning int foo - (**foo)(4) - is a function designator for the function tip.


"What is the function call?"

The function call is actually just the call to a function, like tip(4);.

like image 37
RobertS supports Monica Cellio Avatar answered Oct 23 '22 16:10

RobertS supports Monica Cellio