liveBook · Manning

Call

As explained in Modern C, Third Edition

A function call is an expression or statement that requests execution of a function with supplied arguments.

A call to printf

printf("element %zu is %g, \tits square is %g\n", i, A[i], A[i]*A[i]); requests output using four arguments. The first is a format string; the remaining values supply the numbers placed at its format specifiers. section 1.1

A function call suspends the current function and hands control to the called function. When that function returns, execution continues after the call. C passes argument values: passing i does not let printf change i itself. To give a function access to an object, C can pass its address through a pointer. section 2.4.2 section 19.4

TAKEAWAY: A call has consequences beyond its printed result.

  • Each call creates a new instance of its local objects. Recursive calls therefore have separate locals, although pointers can still give them access to the same data. section 19.4
  • The call operator (...) also applies to function pointers. Even a call written f(3) involves conversion of the function name to a function pointer in C's abstract machine. section 11.4
  • Do not infer left-to-right execution from an argument list. Calls used as separate arguments may run in either order, leaving defined behavior with different possible results when they have side effects. section 19.2
double f(double a);

// Equivalent calls to f, steps in the abstract state machine
f(3);        // Decay → call
(&f)(3);     // Address of → call
(*f)(3);     // Decay → dereference → decay → call
(*&f)(3);    // Address of → dereference → decay → call
(&*f)(3);    // Decay → dereference → address of → call

Equivalent spellings of a call to f make the function-pointer conversion visible. section 11.4

Two possible results

If add(&a, &b) and add(&b, &a) are arguments to one printf call, one complete add call can precede the other or vice versa. Starting with a = 3 and b = 5, the shown program can print either “a = 8, b = 13” or “a = 11, b = 8”. Both outcomes are defined. section 19.2

How Modern C, Third Edition covers it

How deep it goes
Explains arguments, call by value, function-pointer conversion, recursive locals, and sequencing; defers pointer-based access when first introducing calls.
Examples
Uses a formatted printf call, equivalent calls through function pointers, and side-effecting argument calls with two possible outputs.
What it assumes
Assumes basic C statements and variables; introduces calls through printf before deferring address-and-pointer-based access to variables.
What you can do after
Evaluate/understand it: trace control transfer and argument values, and recognize when side-effecting calls can produce different valid results.
How it connects
Connects calls to function pointers, recursion, local objects, pointers, and expression sequencing.

Also explained in

Compare how 7 books explain call →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.