1 //
2 //  "analyse *this"
3 // This is a sample dummy program which demonstrates how can
4 // ncc study pointers to functions to report a nicely connected
5 // call graph.
6 //
7 typedef int (*initcall_t)(void);
8 
init_ext2_fs(void)9 int init_ext2_fs (void)
10 {}
11 
12 static initcall_t __init_module = init_ext2_fs;
13 
14 struct fs_callbacks {
15 	int (*open_file)();
16 	int (*close_file)();
17 	int (*read_bytes)();
18 	int (*write_bytes)();
19 	struct fs_callbacks *next;
20 } FileSystems [10];
21 
open_ext2()22 int open_ext2 () {}
close_ext2()23 int close_ext2 () {}
read_ext2()24 int read_ext2 () {}
write_ext2()25 int write_ext2 () {}
open_ffs()26 int open_ffs () {}
close_ffs()27 int close_ffs () {}
read_ffs()28 int read_ffs () {}
write_ffs()29 int write_ffs () {}
30 
31 struct fs_callbacks FS = {
32 	close_file: close_ext2,
33 	open_file: open_ext2,
34 	read_bytes: read_ext2,
35 	write_bytes: write_ext2
36 };
37 
38 struct redirector {
39 	int (*foo)();
40 } R = { FS.read_bytes };
41 
main()42 int main ()
43 {
44 	struct fs_callbacks *f = &FileSystems [0];
45 	f->open_file = open_ffs;
46 	f->close_file = close_ffs;
47 	f->read_bytes = read_ffs;
48 	f->write_bytes = write_ffs;
49 	application ();
50 }
51 
application()52 void application ()
53 {
54 	void *p;
55 
56 	FileSystems [2].open_file ();
57 	FileSystems [3].next->read_bytes ();
58 	(FileSystems [2].next)->write_bytes ();
59 	((struct fs_callbacks*)p)->next->close_file ();
60 }
61