stack-fcall.c revision c588b205be19f84f757dec6f2e6ed2a157750f97
1#include <unistd.h>
2#include <sys/types.h>
3
4/* Use "volatile" to avoid compiler optimization. */
5
6int f3(int i)
7{
8	static pid_t (* volatile g)(void) = getpid;
9	return g() + i;
10}
11
12int f2(volatile int i)
13{
14	static int (* volatile g)(int) = f3;
15	return g(i) - i;
16}
17
18int f1(volatile int i)
19{
20	static int (* volatile g)(int) = f2;
21	return g(i) + i;
22}
23
24int f0(volatile int i)
25{
26	static int (* volatile g)(int) = f1;
27	return g(i) - i;
28}
29
30int main(int argc, char** argv)
31{
32	static int (* volatile g)(int) = f0;
33	g(argc);
34	return 0;
35}
36