简体   繁体   中英

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?

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.

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);

" 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); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM