Yes, it works just as well.
The function call operator ()just needs the left side, which calculates a pointer to the function, which names perform the functions.
deefence, () .
:
#include <stdio.h>
static int foo(int x) {
return x + 1;
}
static int bar(int x) {
return x - 1;
}
int main(void) {
for (int i = 0; i < 10; ++i)
printf("%d -> %d\n", i, (i & 1 ? foo : bar)(i));
return 0;
}
:
0 -> -1
1 -> 2
2 -> 1
3 -> 4
4 -> 3
5 -> 6
6 -> 5
7 -> 8
8 -> 7
9 -> 10
.
C Python , , Python, C-ish. , .:)